Maps-STL Hackerrank Solution C++
For Explanation Watch Video::
Sample Input
7
1 Jesse 20
1 Jess 12
1 Jess 18
3 Jess
3 Jesse
2 Jess
3 Jess
Sample Output
30
20
0
Code:
#include <cmath>#include <cstdio>#include <vector>#include <iostream>#include <set>#include <map>#include <algorithm>using namespace std;
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int q; cin>>q; map<string,int>m; int type; string name; for(int i=0;i<q;i++){ cin>>type>>name; if(type==1){ int mark; cin>>mark; m[name] += mark; }else if(type==2){ m.erase(name); }else if(type==3){ cout<<m[name]<<"\n"; } } return 0;}
Comments
Post a Comment