- #include
- #define bug printf("************************\n");
- #define fuck(x) cout << #x << " -> " << x << endl
- #define endl '\n'
- #define int long long
- using namespace std;
- constexpr int N = 1e6, inf = 0x3f3f3f3f;
- typedef pair
pii; - string op;
- string name;
- map
arr; - vector
vec; - int cnt;
- #define x first
- #define y second
- void touch()
- {
- cin >> name;
- if (!arr.count(name))
- {
- arr.insert({name, cnt});
- }
- }
- void rm()
- {
- cin >> name;
- arr.erase(name);
- }
- void ls()
- {
- for (auto it : arr)
- {
- vec.push_back(make_pair(it.second, it.first));
- }
- sort(vec.begin(), vec.end());
- for (auto it : vec)
- {
- cout << it.y << endl;
- }
- vec.clear();
- }
- void rename()
- {
- string a, b;
- cin >> a >> b;
- if (arr.count(a))
- {
- int temp = arr[a];
- arr.erase(a);
- arr.insert({b, temp});
- }
- }
- void solve()
- {
- int n;
- cin >> n;
- while (n--)
- {
- cnt++;
- cin >> op;
- if (op == "touch")
- {
- touch();
- }
- else if (op == "rename")
- {
- rename();
- }
- else if (op == "rm")
- {
- rm();
- }
- else if (op == "ls")
- {
- ls();
- }
- }
- }
- signed main()
- {
- ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- solve();
- return 0;
- }