Maps-STL

  • + 0 comments
    int main() {
        /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
        int n;
        int query;
        map<string, int> students;
        cin>>n;
        string name;
        int marks;
        for(int i=0;i<n;i++)
        {
            cin>>query;
            if(query==1)
            {
                cin>>name>>marks;
                students[name]+=marks;
            }
            if(query==2 || query==3)
            {
                cin>>name;
            }
            switch(query)
        {
            case 1: 
            students.insert(make_pair(name,marks)); 
            break;
            
            case 2:
            students.erase(name);
            break;
            
            case 3:
            cout<<students[name]<<"\n";
            break;
        }
        
    }
        return 0;
    }