diff options
| author | Thomas Schmucker <ts@its1.de> | 2023-12-01 21:27:31 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2023-12-01 21:27:31 +0100 |
| commit | 9a164c3f65c01e31a9d1a8578e29b358972ddfed (patch) | |
| tree | d32346277a335540af4967ebdfee38a787529690 /src/01a.cpp | |
| download | advent-of-code-9a164c3f65c01e31a9d1a8578e29b358972ddfed.tar.gz advent-of-code-9a164c3f65c01e31a9d1a8578e29b358972ddfed.tar.bz2 advent-of-code-9a164c3f65c01e31a9d1a8578e29b358972ddfed.zip | |
Lösung für Tag1
Diffstat (limited to 'src/01a.cpp')
| -rw-r--r-- | src/01a.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/01a.cpp b/src/01a.cpp new file mode 100644 index 0000000..1fcc763 --- /dev/null +++ b/src/01a.cpp | |||
| @@ -0,0 +1,23 @@ | |||
| 1 | #include <algorithm> | ||
| 2 | #include <fstream> | ||
| 3 | #include <iostream> | ||
| 4 | #include <string> | ||
| 5 | using namespace std; | ||
| 6 | |||
| 7 | int | ||
| 8 | main() | ||
| 9 | { | ||
| 10 | string digits{ "0123456789" }; | ||
| 11 | fstream input{ "data/01a.txt" }; | ||
| 12 | |||
| 13 | int sum = 0; | ||
| 14 | for ( string line; input >> line; ) { | ||
| 15 | auto first = find_first_of(begin(line), end(line), begin(digits), end(digits)); | ||
| 16 | auto last = find_first_of(rbegin(line), rend(line), begin(digits), end(digits)); | ||
| 17 | |||
| 18 | auto value = (*first - '0') * 10 + (*last - '0'); | ||
| 19 | |||
| 20 | sum += value; | ||
| 21 | } | ||
| 22 | cout << sum << endl; | ||
| 23 | } | ||
