Input Format
The first line of the input contains  where  is the number of queries. The next  lines contain  query each.The first integer,  of each query is the type of the query.If query is of type , it consists of one string and an integer  and  where  is the name of the student and  is the marks of the student.If query is of type  or ,it consists of a single string  where  is the name of the student.
Constraints
Output Format
For queries of type  print the marks of the given student.

hackerrank maps stl problem solution in c++ programming

Maps STL problem solution in C++ programming | HackerRank


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */  
    int q,type;
    cin>>q;
    string name;
    int marks;

    map<string,int> m;
    for(int i=0;i<q;i++)
    {
     cin>>type;
    switch(type) {
    
    case 1:
    cin>>name>>marks;

    if(m.find(name)==m.end())
    m.insert(make_pair(name,marks));
else
m[name]+=marks;

break;

case 2:
cin>>name;
m.erase(name);
break;

case 3:
cin>>name;
m.find(name)!=m.end()?cout<<m.find(name)->second<<endl:cout<<"0"<<endl;
break;

}

return 0;
}