Please Login in order to post a comment
using namespace std;
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ int queries; cin>>queries; mapmp;
while(queries--) { string str; getline(cin>>ws,str); stringstream ss(str); int choice; ss >> choice; switch(choice) { case 1: { string name; int num; ss>>name>>num; mp[name] += num; break; } case 2: { string name = str.substr(2); mp.erase(name); break; } case 3: { string name = str.substr(2); cout<<mp[name]<<"\n"; break; } } } return 0;
}
This code of mine runs successfully across every platforms i tried running but doesn't run in hackerrank... Any idea ?
here is my solution.
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
int queries, q; int y; string x; map<string, int> m; map<string, int>::iterator itr = m.begin(); cin >> queries; for (int i = 0; i < queries; i++) { cin >> q; if (q==1) { cin >> x; cin >> y; m[x] +=y ; } else if(q==2) { cin >> x; m.erase(x); } else if (q==3) { cin >> x; if(m.find(x) != m.end()) { cout << m[x] << endl; } else { cout << 0 << endl; } } } return 0;
map<string, int> m; void add(pair<string, int> p) { m[p.first] += p.second; } void remove(pair<string, int> p) { m.erase(p.first); } void display(pair<string, int> p) { cout<<m[p.first]<<endl; } int main() { int t; cin>>t; while(t--) { int y; pair<string, int> p; cin>>y; switch (y) { case 1: cin>>p.first>>p.second; add(p); break; case 2: cin>>p.first; p.second = 0; remove(p); break; case 3: cin>>p.first; p.second = 0; display(p); break; default: break; } } return 0; }
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ map mp; int i, nums, op, val; string key;
cin >> nums; for (i = 0; i < nums; i++) { cin >> op >> key; if (op == 1) { cin >> val; mp[key] += val; } else if (op == 2) mp.erase(key); else if (op == 3) { if (mp.find(key) != mp.end()) cout << mp[key] << endl; else cout << 0 << endl; } } return 0;
#include <iostream> #include <map> #include <algorithm> #include<assert.h> int main() { std::map<std::string,int>sheet{}; int queries{}; std::cin>>queries; assert(queries>=1 && queries<=1000000); for(int i=0;i<queries;++i) { int q{}; std::string name{}; std::cin>>q; assert(q>=1&&q<=3); std::cin>>name; assert(name.size()>=1 &&name.size()<=6); if(q==1){int marks{};std::cin>>marks;sheet[name]+=marks;} else if(q==2)sheet[name]=0; else if(q==3)std::cout<<sheet[name]<<"\n"; } return 0; }
Seems like cookies are disabled on this browser, please enable them to open this website
include
using namespace std;
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
int queries; cin>>queries; mapmp;
}
This code of mine runs successfully across every platforms i tried running but doesn't run in hackerrank... Any idea ?
here is my solution.
include
include
include
include
include
include
include
using namespace std;
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
}
include
include
include
include
include
include
include
using namespace std;
int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */
map mp; int i, nums, op, val; string key;
}