![在这里插入图片描述](https://img-blog.csdnimg.cn/20200816170617288.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2Jid3FzYg==,size_16,color_FFFFFF,t_70#pic_center)
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<set>
#include<queue>
#include<unordered_map>
#include<cmath>
using namespace std;
const int maxn = 10010;
struct node
{
string id;
int score;
};
bool cmp(node a, node b)
{
return a.score != b.score ? a.score > b.score : a.id < b.id;
}
int main()
{
int n, m,q;
cin >> n >> m;
vector<node>v(n);
string s;
for (int i = 0; i < n; i++)
{
cin >> v[i].id >> v[i].score;
}
for (int i = 1; i <= m; i++)
{
cin >> q >> s;
int people = 0, allscore = 0;
printf("Case %d: %d %s
", i, q, s.c_str());
vector<node>ans;
if (q == 1)
{
for (int j = 0; j < v.size(); j++)
{
if (v[j].id[0] == s[0])
ans.push_back(v[j]);
}
}
else if (q == 2)
{
for (int j = 0; j < v.size(); j++)
{
if (v[j].id.substr(1, 3) == s)
{
people++;
allscore += v[j].score;
}
}
if (people != 0) printf("%d %d
", people, allscore);
}
else if (q == 3)
{
unordered_map<string, int> m;
for (int j = 0; j < n; j++)
if (v[j].id.substr(4, 6) == s) m[v[j].id.substr(1, 3)]++;
for (auto it = m.begin(); it != m.end(); it++)
ans.push_back({ it->first,it->second });
}
sort(ans.begin(), ans.end(), cmp);
for (int j = 0; j < ans.size(); j++)
printf("%s %d
", ans[j].id.c_str(), ans[j].score);
if (((q == 1 || q == 3) && ans.size() == 0) || (q == 2 && people == 0)) printf("NA
");
}
}