#include <bits/stdc++.h>
using namespace std;
int n, a, b, h, z, hb, zb;
string s1, s2;
vector<int> t[50];
void find1(int x) {
for (int i = 0; i < n; i ++) {
for (int j = 0; j < t[i].size(); j ++) {
if (t[i][j] == x) {
h = i, z = j;
}
}
}
}
void guiwei(int x1, int x2) {
for (int i = x2 + 1; i < t[x1].size(); i ++) {
int tmp = t[x1][i];
t[tmp].push_back(tmp);
}
}
void tuo(int x1, int x2) {
for (int i = z; i < t[h].size(); i ++) {
t[hb].push_back(t[h][i]);
}
}
int main() {
cin >> n;
for (int i = 0; i < n; i ++) {
t[i].push_back(i);
}
while (1) {
cin >> s1;
if (s1 == "quit") break;
cin >> a >> s2 >> b;
find1(a);
int h1 = h;
find1(b);
if (h1 == h) continue;
if (s1 == "move" && s2 == "onto") {
find1(a);
guiwei(h, z);
t[h].resize(z);
find1(b);
guiwei(h, z);
t[h].resize(z + 1);
t[h].push_back(a);
}
if (s1 == "move" && s2 == "over") {
find1(a);
guiwei(h, z);
t[h].resize(z);
find1(b);
t[h].push_back(a);
}
if (s1 == "pile" && s2 == "onto") {
find1(b);
hb = h, zb = b;
guiwei(h, z);
t[h].resize(z + 1);
find1(a);
tuo(hb, zb);
t[h].resize(z);
}
if (s1 == "pile" && s2 == "over") {
find1(b);
hb = h, zb = b;
find1(a);
tuo(hb, zb);
t[h].resize(z);
}
/* for (int i = 0; i < n; i ++) {
for (int j = 0; j < t[i].size(); j ++) {
cout << t[i][j] << ' ';
}
cout << endl;
}*/
}
for (int i = 0; i < n; i ++) {
cout << i << ": ";
for (int j = 0; j < t[i].size(); j ++) {
cout << t[i][j] << ' ';
}
cout << endl;
}
return 0;
}
样例过了,但是WA0分 求助各位大佬纠错