Maps-STL-C++
int main() {
int q, type; cin >> q;
map<string,int> clas; string name;
for (int i(0), mark; i<q; ++i)
{
cin >> type >> name;
if (type == 1){
cin >> mark;
clas[name] += mark;
}
else if (type == 2)
clas.erase(name);
else
cout << clas[name] << "\n";
}
return 0;
}
............................................
int n;cin>>n;map<string,int>mp;for (int i = 0; i<n; i++) {int a;cin>>a;if (a == 1) {int b;string c;// cin>>b>>c;cin>>b;// mp.insert(make_pair(c,b));mp[c] += b;}if (a == 2) {string d;cin>>d;mp.erase(d);}if (a == 3) {string e;cin>>e;cout<<mp[e]<<endl;}}for(auto itr = mp.begin(); itr != mp.end(); itr++){cout<<itr->first;}
Comments
Post a Comment