Branch data Line data Source code
1 : : #include <iostream>
2 : : #include <fstream>
3 : : #include <regex>
4 : : #include <string>
5 : : #include <iterator>
6 : : #include <cstdint>
7 : : using namespace std;
8 : :
9 : 2 : int main() {
10 : 2 : ifstream file("input.txt");
11 [ + + ]: 2 : if (!file) {
12 : 1 : cerr << "Error: Could not open input file.\n";
13 : 1 : return 1;
14 : : }
15 : 1 : string content((istreambuf_iterator<char>(file)), {});
16 : 1 : const regex r(R"(mul\((\d{1,3}),(\d{1,3})\))");
17 : 1 : uint64_t sum = 0;
18 [ + + ]: 738 : for (sregex_iterator it(content.begin(), content.end(), r), end; it != end; ++it) {
19 : 737 : sum += stoi((*it)[1]) * stoi((*it)[2]);
20 : 1 : }
21 : 1 : cout << sum;
22 [ + + ]: 3 : }
|