Skip to content

Instantly share code, notes, and snippets.

@lazycipher
Created May 8, 2019 13:26
Show Gist options
  • Save lazycipher/5cf1a1842e860fbcc5cdf08c3611d375 to your computer and use it in GitHub Desktop.
Save lazycipher/5cf1a1842e860fbcc5cdf08c3611d375 to your computer and use it in GitHub Desktop.
Maps STL HackerRank Problem
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <set>
#include <map>
#include <algorithm>
#include<string>
using namespace std;
int main() {
int q;
cin>>q;
map<string, int> m;
map<string, int>::iterator itr;
while(q){
int val, marks;
string name;
cin>>val>>name;
itr = m.find(name);
switch(val){
case 1:
cin>>marks;
if(itr!=m.end()){
m[name] += marks;
}else{
m.insert(make_pair(name, marks));
}
break;
case 2:
if(itr!=m.end()){
m.erase(name);
}
break;
case 3:
if(itr!=m.end()){
cout<<m[name]<<endl;
}else{
cout<<"0"<<endl;
}
break;
}
q--;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment