You are viewing a single comment's thread. Return to all comments →
Here is my solution!
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <string> #include <algorithm> #include <map> using namespace std; int main() { ios::sync_with_stdio(false); cin.tie(0); map<string, int> answer_sheet; int queries, type, y; string x; cin >> queries; for (int i = 0; i < queries; i++) { cin >> type >> x; auto it = answer_sheet.find(x); if (type == 1) { cin >> y; if (it == answer_sheet.end()) { answer_sheet.insert({x, y}); } else { answer_sheet[x] += y; } } else if (type == 2) { if (it == answer_sheet.end()) { answer_sheet.insert({x, 0}); } else { answer_sheet[x] = 0; } } else { if (it == answer_sheet.end()) { cout << "0\n"; } else { cout << answer_sheet[x] << "\n"; } } } return 0; }
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 →
Here is my solution!