blob: b3bc1e8c24de2b5b78a0e48a351091f78fd9cd8c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <deque>
using namespace std;
int
main()
{
string line;
vector<deque<char>> 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;
}
|