advent-of-code/2023/4/main-1.cpp
2023-12-03 21:53:11 -08:00

36 lines
636 B
C++

#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int ret = 0;
string line;
while (getline(cin, line) && !line.empty()) {
int count = 1;
int start = line.find(':');
int bar = line.find('|');
string left = line.substr(start + 2, bar - start - 3);
string right = line.substr(bar + 2);
istringstream lss(left), rss(right);
vector<int> rv;
while (!rss.eof()) {
int n;
rss >> n;
rv.push_back(n);
}
while (!lss.eof()) {
int n;
lss >> n;
for (auto no : rv) {
if (no == n)
count <<= 1;
}
}
ret += count >> 1;
}
cout << ret << '\n';
}