Maps-STL

  • + 0 comments
    #include <cmath>
    #include <cstdio>
    #include <vector>
    #include <iostream>
    #include <algorithm>
    #include <map>
    using namespace std;
    
    
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int t;
        cin>>t;
        map<string,int>mp;
        while(t--){
            int a;
            cin>>a;
            string s;
            cin>>s;
            if(a==1){
                int marks;
                cin>>marks;
                auto it=mp.find(s);
                if(it!=mp.end()){
                    mp[s]+=marks;
                }else{
                    mp.insert(make_pair(s,marks));
                }
            }
            if(a==2){
                mp.erase(s);
            }
            if(a==3){
                if(mp.find(s)!=mp.end()){
                    cout<<mp[s]<<endl;
                }else{
                    cout<<0<<endl;
                }
            }
        }
        return 0;
    }