From f3a189826ac3d8bc69ea5c512e846ecb64b2069e Mon Sep 17 00:00:00 2001 From: dzwdz Date: Mon, 5 Dec 2022 06:33:34 +0100 Subject: day 5: a painfull attemt to get onto the leaderboards i did part 2 first lmao --- 22.5/main.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 22.5/main.cpp (limited to '22.5/main.cpp') 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 +#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; +} -- cgit 1.4.1-2-gfad0