File tree 3 files changed +146
-0
lines changed
3 files changed +146
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include " common.h"
2
+
3
+ namespace {
4
+ long p1 (const auto &input) {
5
+ long m{0 };
6
+ long c{0 };
7
+ for (const auto &l : input) {
8
+ if (l.empty ()) {
9
+ m = std::max (m, c);
10
+ c = 0 ;
11
+ } else {
12
+ c += std::atol (l.c_str ());
13
+ }
14
+ }
15
+ return std::max (m, c);
16
+ }
17
+
18
+ long p2 (const auto &input) {
19
+ std::vector<long > m;
20
+ long c{0 };
21
+ for (const auto &l : input) {
22
+ if (l.empty ()) {
23
+ m.emplace_back (-c);
24
+ c = 0 ;
25
+ } else {
26
+ c += std::atol (l.c_str ());
27
+ }
28
+ }
29
+ m.emplace_back (-c);
30
+ std::sort (m.begin (), m.end ());
31
+ return std::abs (m[0 ] + m[1 ] + m[2 ]);
32
+ }
33
+ } // namespace
34
+
35
+ int main () {
36
+ const auto &input = gb::advent2021::readIn ();
37
+ gb::advent2021::writeOut (std::to_string (p1 (input)));
38
+ gb::advent2021::writeOut (std::to_string (p2 (input)));
39
+ }
Original file line number Diff line number Diff line change
1
+ #include < algorithm>
2
+ #include < bitset>
3
+ #include < climits>
4
+ #include < cmath>
5
+ #include < cstdint>
6
+ #include < cstdio>
7
+ #include < deque>
8
+ #include < functional>
9
+ #include < iostream>
10
+ #include < iterator>
11
+ #include < map>
12
+ #include < memory>
13
+ #include < numeric>
14
+ #include < set>
15
+ #include < sstream>
16
+ #include < stack>
17
+ #include < string>
18
+ #include < tuple>
19
+ #include < unordered_map>
20
+ #include < unordered_set>
21
+ #include < variant>
22
+ #include < vector>
23
+
24
+ using vs = std::vector<std::string>;
25
+
26
+ namespace gb ::advent2021 {
27
+ std::vector<std::string> readIn () {
28
+ std::vector<std::string> lines;
29
+ for (std::string l; getline (std::cin, l);) {
30
+ lines.emplace_back (l);
31
+ }
32
+ return lines;
33
+ }
34
+
35
+ void writeOut (std::string s) { std::cout << s << std::endl; }
36
+ } // namespace gb::advent2021
Original file line number Diff line number Diff line change
1
+ project (' advent2022' , ' cpp' ,
2
+ version : ' 0.1' ,
3
+ default_options : [' warning_level=3' , ' cpp_std=c++2a' ])
4
+
5
+ executable (' 1' ,
6
+ ' 1.cpp' ,
7
+ dependencies : [])
8
+
9
+ # executable('2',
10
+ # '2.cpp',
11
+ # dependencies: [])
12
+
13
+ # executable('3',
14
+ # '3.cpp',
15
+ # dependencies: [])
16
+
17
+ # executable('4',
18
+ # '4.cpp',
19
+ # dependencies: [])
20
+
21
+ # executable('5',
22
+ # '5.cpp',
23
+ # dependencies: [])
24
+
25
+ # executable('6',
26
+ # '6.cpp',
27
+ # dependencies: [])
28
+
29
+ # executable('7',
30
+ # '7.cpp',
31
+ # dependencies: [])
32
+
33
+ # executable('8',
34
+ # '8.cpp',
35
+ # dependencies: [])
36
+
37
+ # executable('9',
38
+ # '9.cpp',
39
+ # dependencies: [])
40
+
41
+ # executable('10',
42
+ # '10.cpp',
43
+ # dependencies: [])
44
+
45
+ # executable('11',
46
+ # '11.cpp',
47
+ # dependencies: [])
48
+
49
+ # executable('12',
50
+ # '12.cpp',
51
+ # dependencies: [])
52
+
53
+ # executable('13',
54
+ # '13.cpp',
55
+ # dependencies: [])
56
+
57
+ # executable('14',
58
+ # '14.cpp',
59
+ # dependencies: [])
60
+
61
+ # executable('15',
62
+ # '15.cpp',
63
+ # dependencies: [])
64
+
65
+ # executable('16',
66
+ # '16.cpp',
67
+ # dependencies: [])
68
+
69
+ # executable('17',
70
+ # '17.cpp',
71
+ # dependencies: [])
You can’t perform that action at this time.
0 commit comments