#include #include #include #include #include using namespace std; int main() { string line; vector> crates; while (getline(cin, line)) { if (line.size() < 2) continue; if (line[1] == '1') break; int clen = (line.size() + 1) / 4; while (crates.size() < clen) crates.emplace_back(); for (int i = 0; i < clen; i++) { int b = i * 4; if (line[b] == '[') { crates[i].push_front(line[b+1]); } } cout << line << endl; } for (auto &s : crates) { for (char c : s) cout << c; cout << endl; } int c, from, to; while (scanf(" move %d from %d to %d", &c, &from, &to) == 3) { from--; to--; int fp = crates[from].size() - c; printf("%d %d>%d %d\n", c, from, to, fp); if (0) { // part 1 while(c--) { crates[to].push_back(crates[from].back()); crates[from].pop_back(); } } else { if (fp < 0) fp = crates[from].size(); for (int i = 0; i < c; i++) crates[to].push_back(crates[from][fp + i]); crates[from].erase(crates[from].begin() + fp, crates[from].end()); } } for (auto &s : crates) { cout << s.back(); } cout << endl; }