Files
advent-of-code/2015/puzzle-12-01.cc
2021-12-01 20:31:53 +00:00

31 lines
614 B
C++

#include <cassert>
#include <functional>
#include <iostream>
#include <map>
#include <regex>
#include <set>
#include <string>
#include <variant>
int parse_numbers(std::string const &s) {
static const std::regex re("-?\\d+");
std::string left = s;
std::smatch m;
int acc = 0;
while (std::regex_search(left, m, re)) {
acc += std::stoi(m.str(0));
left = m.suffix();
}
return acc;
}
int main(int argc, char **argv) {
int acc = 0;
for (std::string line; std::getline(std::cin, line);) {
acc += parse_numbers(line);
}
std::cout << "Accumulated value: " << acc << "\n";
return 0;
}