Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- #include<algorithm>
- #define endl '\n'
- using namespace std;
- int main() {
- cin.tie(nullptr);
- ios::sync_with_stdio(false);
- int n, a, b;
- string str1, str2;
- while (cin >> n) {
- vector<pair<size_t, size_t>> p(n);
- vector<vector<int>> v(n);
- for (int i = 0; i != n; i++)
- v[i].assign({i}), p[i] = {i, 0};
- while (cin >> str1) {
- if (str1 == "quit") break;
- cin >> a >> str2 >> b;
- if (a == b || p[a].first == p[b].first) continue;
- auto pb = [&](auto pos) {
- auto x = p[pos].first, y = p[pos].second + 1;
- vector<int> tmp(v[x].begin() + y, v[x].end());
- v[x].erase(v[x].begin() + y, v[x].end());
- for (const auto& i : tmp)
- v[i].emplace_back(i), p[i] = {i, v[i].size() - 1};
- };
- if (str1 == "move") pb(a);
- if (str2 == "onto") pb(b);
- auto x = p[a].first, y = p[a].second;
- vector<int> tmp(v[x].begin() + y, v[x].end());
- v[x].erase(v[x].begin() + y, v[x].end());
- x = p[b].first;
- for (const auto& i : tmp)
- v[x].emplace_back(i), p[i] = {x, v[x].size() - 1};
- }
- for (size_t i = 0; i < v.size(); i++) {
- cout << i << ": ";
- for (const auto& j : v[i])
- cout << j << ' ';
- cout << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment