aboutsummaryrefslogtreecommitdiff
path: root/src/01b.cpp
diff options
context:
space:
mode:
authorThomas Schmucker <ts@its1.de>2023-12-02 09:08:01 +0100
committerThomas Schmucker <ts@its1.de>2023-12-02 09:08:01 +0100
commitdcca312c9b1b5311c30d1f1ade9765d2a102913d (patch)
tree686a6779f29667ef601eeeaa46a7e9c97a8fc317 /src/01b.cpp
parentf05f4b7f8846238b2402940731f7f2d2b7ba0f55 (diff)
downloadadvent-of-code-dcca312c9b1b5311c30d1f1ade9765d2a102913d.tar.gz
advent-of-code-dcca312c9b1b5311c30d1f1ade9765d2a102913d.tar.bz2
advent-of-code-dcca312c9b1b5311c30d1f1ade9765d2a102913d.zip
Bessere Dateinamen
Diffstat (limited to 'src/01b.cpp')
-rw-r--r--src/01b.cpp57
1 files changed, 0 insertions, 57 deletions
diff --git a/src/01b.cpp b/src/01b.cpp
deleted file mode 100644
index 91ba7b7..0000000
--- a/src/01b.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
1#include <algorithm>
2#include <fstream>
3#include <iostream>
4#include <map>
5#include <string>
6#include <vector>
7using namespace std;
8
9int
10main()
11{
12 map<string, int> map{
13 { "0", 0 },
14 { "1", 1 },
15 { "2", 2 },
16 { "3", 3 },
17 { "4", 4 },
18 { "5", 5 },
19 { "6", 6 },
20 { "7", 7 },
21 { "8", 8 },
22 { "9", 9 },
23 { "one", 1 },
24 { "two", 2 },
25 { "three", 3 },
26 { "four", 4 },
27 { "five", 5 },
28 { "six", 6 },
29 { "seven", 7 },
30 { "eight", 8 },
31 { "nine", 9 },
32 };
33
34 fstream input{ "data/01a.txt" };
35
36 auto sum = 0;
37 for ( string line; input >> line; ) {
38 string sub;
39 vector<int> digits;
40
41 for ( auto ch: line ) {
42 sub += ch;
43
44 for ( const auto& word: map ) {
45 if ( sub.ends_with(word.first) ) {
46 digits.push_back(word.second);
47 }
48 }
49 }
50
51 auto first = digits.front();
52 auto last = digits.back();
53
54 sum += (first * 10) + last;
55 }
56 cout << sum << endl;
57}