summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--22.5/main.cpp54
1 files changed, 54 insertions, 0 deletions
diff --git a/22.5/main.cpp b/22.5/main.cpp
new file mode 100644
index 0000000..b3bc1e8
--- /dev/null
+++ b/22.5/main.cpp
@@ -0,0 +1,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;
+}