-
Notifications
You must be signed in to change notification settings - Fork 223
/
Copy pathcpp-maps.cpp
42 lines (39 loc) · 935 Bytes
/
cpp-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
41
42
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;
int main() {
int q;
cin >> q;
map<string, int> m;
for (int i = 0; i < q; i++) {
int type, num;
string name;
cin >> type;
switch(type) {
case 1:
cin >> name >> num;
if (m.find(name) == m.end())
m.insert(make_pair(name, num));
else
m[name] += num;
break;
case 2:
cin >> name;
m.erase(name);
break;
case 3:
cin >> name;
if (m.find(name) == m.end())
cout << "0" << endl;
else
cout << m[name] << endl;
break;
}
}
return 0;
}