blob: 3034d43ef88539c12ed0f62ab9d702b98cb41b29 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
#include <iostream>
#include <fstream>
template<typename Iter>
int search(Iter from, Iter to)
{
while(from < to)
{
char c = *(from++);
if (std::isdigit(c))
{
return c - '0';
}
}
return 0;
}
int main(void)
{
int answer{};
std::ifstream input{ "./resources/input.txt" };
if (input)
{
std::string line;
while(not std::getline(input, line).eof())
{
answer += 10 * search(line.begin(), line.end());
answer += search(line.rbegin(), line.rend());
}
}
input.close();
std::cout << answer << std::endl;
return 0;
}
|