You are viewing a single comment's thread. Return to all comments →
#include <iostream> #include <map> int main() { unsigned int queries; std::cin >> queries; std::map<std::string, unsigned short> studentData; while (queries) { unsigned short queryType; std::cin >> queryType; std::string studentName; if (queryType == 1) { unsigned short studentMark; std::cin >> studentName >> studentMark; studentData[studentName] += studentMark; } else { std::cin >> studentName; switch (queryType) { case 2: studentData[studentName] = 0; break; case 3: std::cout << studentData[studentName] << '\n'; break; } } queries--; } return 0; }
Notice that we do not actually need to refer the student's mark unless the user enters '1', so you can declare the variable only in that case.
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 →
Notice that we do not actually need to refer the student's mark unless the user enters '1', so you can declare the variable only in that case.