You are viewing a single comment's thread. Return to all comments →
Solution for c++14
#include <iostream> #include <string> #include <map> using namespace std; int main() { int q; cin >> q; map<string, int> students_marks; while (q--) { int type; cin >> type; string x; cin >> x; switch (type) { case 1: { int y; cin >> y; auto pair = students_marks.insert(make_pair(x, y)); if (!pair.second) pair.first->second += y; break; } case 2: { students_marks.erase(x); break; } default: { if (students_marks.find(x) != students_marks.end()) cout << students_marks.at(x) << endl; else cout << 0 << endl; break; } } } }
Seems like cookies are disabled on this browser, please enable them to open this website
Maps-STL
You are viewing a single comment's thread. Return to all comments →
Solution for c++14