Created
April 3, 2017 03:28
-
-
Save Panchatcharam/0055e1f9f2276bf519c314e8755f0961 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <algorithm> | |
#include <string> | |
#include <map> | |
using namespace std; | |
int main() | |
{ | |
unsigned long totalQuery = 0; | |
unsigned int query = 0; | |
string name(""); | |
map<string, unsigned int> scoreContainer = {}; | |
unsigned int score = 0; | |
cin >> totalQuery; | |
if (!((totalQuery >= 1) && (totalQuery <= 100000) )) | |
{ | |
return 0; | |
} | |
for (auto count = static_cast<unsigned long>(0); count < totalQuery ; ++count) | |
{ | |
cin >> query; | |
cin >> name; | |
cin >> score; | |
if ( !( (query >= 1 && query <= 3) && (name != "") && (score >= 1 && score <= 1000)) ) | |
{ | |
return 0; | |
} | |
switch(query) | |
{ | |
case 1: | |
{ | |
auto it = scoreContainer.find(name); | |
if (it != scoreContainer.end()) | |
{ | |
it->second += score; | |
} | |
else | |
{ | |
scoreContainer[name] = score; | |
} | |
} | |
break; | |
case 2: | |
{ | |
auto it = scoreContainer.find(name); | |
if (it != scoreContainer.end()) | |
{ | |
scoreContainer.erase(it); | |
} | |
} | |
break; | |
case 3: | |
{ | |
auto it = scoreContainer.find(name); | |
if (it != scoreContainer.end()) | |
{ | |
cout << it->second << endl; | |
} | |
else | |
{ | |
cout << 0 << endl; | |
} | |
} | |
break; | |
} | |
name.clear(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample C++ example to illustrate the usage of map with auto keyword.