#include #include #include int update(int status[9], char c) { static const std::vector words{ "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; int ret{}; for (int a{}; a < words.size(); ++a) { if (words[a][status[a]] == c) { ++status[a]; } else { status[a] = words[a][0] == c; } if (status[a] == words[a].size()) { ret = a+1; } } return ret; } int search(const std::string& line) { int status[9]{}; int fst{}, lst{}; for (char c : line) { int d = update(status, c); if (std::isdigit(c)) { d = c - '0'; } if (d > 0) { if (fst <= 0) { fst = d; } lst = d; } } return fst * 10 + lst; } int main(void) { int answer{}; std::ifstream input{ "./resources/input.txt" }; if (input) { std::string line; while(not std::getline(input, line).eof()) { answer += search(line); } } input.close(); std::cout << answer << std::endl; return 0; }