advent-of-code/2023/2/main-2.cpp

44 lines
675 B
C++
Raw Normal View History

2023-12-02 21:35:11 -08:00
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
auto& cin = std::cin >> noskipws;
int ret = 0, id = 0, r = 0, g = 0, b = 0;
for (;;) {
char c;
cin >> c;
switch (c) {
case 'G':
cin >> c; cin >> c; cin >> c; cin >> c;
cin >> id;
break;
case ':': case ',': case ';':
cin >> c;
int n;
cin >> n;
cin >> c;
cin >> c;
switch (c) {
case 'r': r = max(n, r); break;
case 'g': g = max(n, g); break;
case 'b': b = max(n, b); break;
}
break;
case '\n':
if (cin.eof())
goto end;
ret += r * g * b;
r = 0; g = 0; b = 0;
break;
}
}
end:
cout << ret << '\n';
}