2023 day 2

This commit is contained in:
eriedaberrie 2023-12-02 21:35:11 -08:00
parent ce72d1e8bc
commit 7697111267
3 changed files with 103 additions and 1 deletions

4
.gitignore vendored
View file

@ -1,4 +1,6 @@
*.fasl *.fasl
*.o *.o
*.hi *.hi
data.txt *data*.txt
main
main-[0-9]

57
2023/2/main-1.cpp Normal file
View file

@ -0,0 +1,57 @@
#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;
bool isPossible = true;
for (;;) {
char c;
cin >> c;
switch (c) {
case 'G':
cin >> c; cin >> c; cin >> c; cin >> c;
cin >> id;
break;
case ':': case ',': case ';':
if (!isPossible)
break;
cin >> c;
int n;
cin >> n;
cin >> c;
cin >> c;
switch (c) {
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':
if (cin.eof())
goto end;
if (isPossible)
ret += id;
else
isPossible = true;
break;
}
}
end:
cout << ret << '\n';
}

43
2023/2/main-2.cpp Normal file
View file

@ -0,0 +1,43 @@
#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';
}