You are viewing a single comment's thread. Return to all comments →
can somebody tell me what is wrong with my code?
I am getting wrong for testcases 1, 3, 12 ,13
#include <cmath> #include <cstdio> #include <vector> #include <iostream> #include <set> #include <map> #include <iterator> #include <algorithm> using namespace std; int main() { /* Enter your code here. Read input from STDIN. Print output to STDOUT */ map<string, int> m; map<string, int>::iterator it; int q, type, marks; cin >> q; string name; while (!cin.eof()) { cin >> type; if (type == 1) { cin >> name >> marks; // it = m.find(name); // if (it != m.end()) { // marks += it->second; // } // cout << "1 " << name << " " << marks << endl; m[name] += marks; } else if (type == 2) { cin >> name; // cout << "2" << " " << name << endl; m.erase(name); } else if (type == 3) { cin >> name; // cout << "3" << " " << name << endl; it = m.find(name); if (it != m.end()) { cout << it->second << endl; } else { cout << 0 << endl; } } } 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 →
can somebody tell me what is wrong with my code?
I am getting wrong for testcases 1, 3, 12 ,13