Skip to content

Instantly share code, notes, and snippets.

@Panchatcharam
Created April 3, 2017 03:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Panchatcharam/0055e1f9f2276bf519c314e8755f0961 to your computer and use it in GitHub Desktop.
Save Panchatcharam/0055e1f9f2276bf519c314e8755f0961 to your computer and use it in GitHub Desktop.
#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;
}
@Panchatcharam
Copy link
Author

Sample C++ example to illustrate the usage of map with auto keyword.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment