-
-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathmaps.cpp
40 lines (28 loc) · 743 Bytes
/
maps.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
map<string, int> m;
m["one"] = 1;
m["two"] = 2;
m["three"] = 3;
int one_plus_two = m["one"] + m["two"];
cout << one_plus_two << endl;
int total = 0;
for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it)
total += it->second;
cout << total << endl;
if (m.find("two") != m.end())
m.erase(m.find("two"));
total = 0;
for (map<string, int>::iterator it = m.begin(); it != m.end(); ++it)
total += it->second;
cout << total << endl;
if (m.find("one") != m.end()) {
cout << m.find("one")->first << endl;
m.find("one")->second++;
cout << m.find("one")->second << endl;
}
return 0;
}