aboutsummaryrefslogtreecommitdiff
path: root/src/01a.cpp
blob: 1fcc763de8bd86729582ea59a964b768cb9a5f17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
using namespace std;

int
main()
{
	string  digits{ "0123456789" };
	fstream input{ "data/01a.txt" };

	int sum = 0;
	for ( string line; input >> line; ) {
		auto first = find_first_of(begin(line), end(line), begin(digits), end(digits));
		auto last  = find_first_of(rbegin(line), rend(line), begin(digits), end(digits));

		auto value = (*first - '0') * 10 + (*last - '0');

		sum += value;
	}
	cout << sum << endl;
}