advent-of-code/2024/day03/part1.cc

19 lines
495 B
C++
Raw Normal View History

2024-12-14 04:53:32 +00:00
#include <iostream>
#include <regex>
#include <string>
int main() {
std::string line;
std::regex r{"mul\\((\\d+),(\\d+)\\)"};
int result = 0;
while (std::getline(std::cin, line)) {
for (std::sregex_iterator iter{line.begin(), line.end(), r}, iter_end; iter != iter_end; iter++) {
const auto &match = *iter;
const auto op1 = std::stoi(match[1]), op2 = std::stoi(match[2]);
result += op1 * op2;
}
}
std::cout << result << std::endl;
return EXIT_SUCCESS;
}