-
Notifications
You must be signed in to change notification settings - Fork 0
/
Maps-STL.cpp
55 lines (52 loc) · 1.07 KB
/
Maps-STL.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
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <iostream>
#include<map>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
//cin.tie(NULL);
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif
map<string, int>mp;
map<string, int>::iterator it;
int Q,type,Y;
cin >> Q;
string X;
for (size_t i = 0; i < Q; i++)
{
cin >> type;
if(type == 1)
{
// cout << "1 has been fired " << endl;
cin >> X >> Y;
it = mp.find(X);
if(it != mp.end()) {
it->second += Y;
}else {
mp.insert({X,Y});
}
}
if(type == 2)
{
// cout << "2 has been fired " << endl;
cin >> X;
it = mp.find(X);
if(it != mp.end()) {
mp.erase(X);
}
}
if(type==3)
{
//cout << "3 has been fired " << endl;
cin >> X;
it = mp.find(X);
if(it != mp.end()) {
cout << it->second << endl;
}else {
cout << 0<<endl;
}
}
}
return 0;
}