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;}
#include<cmath>#include<cstdio>#include<vector>#include<iostream>#include<set>#include<map>#include<algorithm>usingnamespacestd;intmain(){/* Enter your code here. Read input from STDIN. Print output to STDOUT */intq;cin>>q;map<string,int>mp;for(inti=0;i<q;i++){inttype;cin>>type;if(type==1){stringname;intmarks;cin>>name>>marks;mp[name]+=marks;}elseif(type==2){stringname;cin>>name;mp.erase(name);}elseif(type==3){stringname;cin>>name;cout<<mp[name]<<endl;}}return0;}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Here is - hackerrank maps - stl problem solution