diff options
Diffstat (limited to '2024/01/day01b.cpp')
| -rw-r--r-- | 2024/01/day01b.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/2024/01/day01b.cpp b/2024/01/day01b.cpp new file mode 100644 index 0000000..91ef0db --- /dev/null +++ b/2024/01/day01b.cpp | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | #include <iostream> | ||
| 2 | #include <algorithm> | ||
| 3 | #include <vector> | ||
| 4 | using namespace std; | ||
| 5 | |||
| 6 | int main() { | ||
| 7 | int x, y, tot; | ||
| 8 | vector<int> v, w; | ||
| 9 | |||
| 10 | while (cin >> x >> y) { | ||
| 11 | v.push_back(x); | ||
| 12 | w.push_back(y); | ||
| 13 | } | ||
| 14 | |||
| 15 | tot = 0; | ||
| 16 | for (unsigned i = 0; i < v.size(); i++) | ||
| 17 | tot += v[i] * count(w.begin(), w.end(), v[i]); | ||
| 18 | |||
| 19 | cout << tot << endl; | ||
| 20 | return 0; | ||
| 21 | } | ||
