00 /*
01  * maps.cpp
02  *
03  *      Author: Simonas Saltenis / Kurt Nørmark
04  */
05 
06 #include <iostream>
07 #include <string>
08 #include <map>
09 
10 using namespace std;
11 
12 void readitems(map<string, int> &m)
13 {
14    string word;
15    int val;
16 
17    while (cin >> word >> val)
18       m[word] += val;           // Relies on the default map value initialization.
19 }
20 
21 int main()
22 {
23     map<string,int> str_count;       // All values in the map are initialized to 0.
24 
25     readitems(str_count);
26 
27     int total = 0;
28 
29     // Accumulating total - and printing - via use of range-for:
30     for(const auto& [key, value]: str_count)
31     {
32        total += value;
33        cout << key << "\t\t" << value << endl;
34     }
35 
36     cout << "-------------------------\ntotal\t\t" << total << endl;
37 }
38 
39 
40