We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intq_no,q_type,marks;stringname;map<string,int>m;map<string,int>::iteratorit;cin>>q_no;while(q_no){cin>>q_type;switch(q_type){case1:cin>>name>>marks;it=m.find(name);if(it!=m.end()){m[name]+=marks;}else{m.insert(make_pair(name,marks));}break;case2:cin>>name;m[name]=0;break;case3:cin>>name;it=m.find(name);(it!=m.end())?cout<<m[name]<<endl:cout<<0<<endl;break;}q_no--;}return0;}
intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intn;intquery;map<string,int>students;cin>>n;stringname;intmarks;for(inti=0;i<n;i++){cin>>query;if(query==1){cin>>name>>marks;students[name]+=marks;}if(query==2||query==3){cin>>name;}switch(query){case1:students.insert(make_pair(name,marks));break;case2:students.erase(name);break;case3:cout<<students[name]<<"\n";break;}}return0;}
map map1; string x; int n,k,y; cin>>n; while(n--){ cin>>k; if(k==1){ cin>>x; cin>>y; if(map1.count(x)==1){ y+=map1[x]; map1[x]=y; }else{
map1[x]=y; } } else if(k==2){ cin>>x; map1[x]=0; } else if(k==3){ cin>>x; cout<
Here is - hackerrank maps - stl problem solution