Maps-STL

  • + 0 comments
    map<string,int> studentMarks;
    int n,query,marks;
    cin >> n;
    string name;
    
    for(int i=0; i<n; ++i){
        cin >> query;
    
        if(query == 1){
            cin >> name >> marks;
            studentMarks[name] += marks;
        }
        else if(query == 2){
            cin >> name;
            studentMarks.erase(name);
        }
        else if(query == 3){
            cin >> name;
            if(studentMarks.find(name) != studentMarks.end()){
                cout << studentMarks[name];
            }
            else{
                cout << 0;
            }
        }
    }