File tree 1 file changed +55
-0
lines changed
1 file changed +55
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < iostream>
2
+ #include < fstream>
3
+ #include < string>
4
+ #include < vector>
5
+ #include < map>
6
+ #include < numeric>
7
+ #include < algorithm>
8
+ #include < iterator>
9
+
10
+
11
+ struct line_t : std::string
12
+ {};
13
+
14
+ std::istream & operator >>( std::istream & is, line_t & line )
15
+ {
16
+ return std::getline ( is, line );
17
+ }
18
+
19
+ std::map< std::string, uint64_t > table
20
+ {
21
+ { " A X" , 3 },
22
+ { " A Y" , 4 },
23
+ { " A Z" , 8 },
24
+ { " B X" , 1 },
25
+ { " B Y" , 5 },
26
+ { " B Z" , 9 },
27
+ { " C X" , 2 },
28
+ { " C Y" , 6 },
29
+ { " C Z" , 7 }
30
+ };
31
+
32
+
33
+ int main ( int argc, char * argv[] )
34
+ {
35
+ if ( argc < 2 )
36
+ return 0 ;
37
+
38
+ std::ifstream ifs ( argv[ 1 ] );
39
+
40
+ uint64_t const result{
41
+ std::transform_reduce (
42
+ std::istream_iterator< line_t >( ifs ), std::istream_iterator< line_t >(),
43
+ 0ULL ,
44
+ std::plus{},
45
+ []( std::string const & s ) -> uint64_t
46
+ {
47
+ return table[ s ];
48
+ }
49
+ )
50
+ };
51
+
52
+ std::cout << " result = " << result << std::endl;
53
+
54
+ return 0 ;
55
+ }
You can’t perform that action at this time.
0 commit comments