advent-of-code/2023/2/main-1.cpp
2023-12-03 17:13:16 -08:00

53 lines
758 B
C++

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int ret = 0, id = 0;
bool isPossible = true;
while (!cin.eof()) {
switch (cin.get()) {
case 'G':
cin.ignore(4);
cin >> id;
break;
case ':': case ',': case ';':
if (!isPossible)
break;
cin.ignore(1);
int n;
cin >> n;
cin.ignore(1);
switch (cin.get()) {
case 'r':
if (n > 12)
isPossible = false;
break;
case 'g':
if (n > 13)
isPossible = false;
break;
case 'b':
if (n > 14)
isPossible = false;
break;
}
break;
case '\n':
case EOF:
if (isPossible) {
ret += id;
id = 0;
} else {
isPossible = true;
}
break;
}
}
cout << ret << '\n';
}