Maps-STL

  • + 1 comment

    passed all the tests: int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int q,i; string x; int y; int a; map m; cin>>q; for(i=0;i

        cin>>a;
        cin>>x;
    
        if(a==1){
        cin>>y;
            map<string, int>::iterator itr=m.find(x);
       if (itr==m.end()){
            m.insert(make_pair(x,y));
            }
            else { m[x]+=y;}
    
        }
        else if(a==2){
            m.erase(x);
        }
        else if(a==3){
            map<string, int>::iterator itr=m.find(x);
       if (itr==m.end()){
                cout<<"0"<<endl;
            }
            else
                cout<<m[x]<<endl;
    
        }
        else break;
    
    
    }
    return 0;
    

    }