1153 Decode Registration Card of PAT (25 分)
sb题,不想过多描述==。
struct Node
{
string id;
int score;
bool operator<(const Node &W) const
{
if(score != W.score) return score > W.score;
return id < W.id;
}
};
unordered_map<char,vector<Node>> mp1;
unordered_map<string,PII> mp2;
unordered_map<string,vector<Node>> mp3;
int n,m;
int main()
{
cin>>n>>m;
for(int i=0;i<n;i++)
{
string id;
int score;
cin>>id>>score;
mp1[id[0]].pb({id,score});
mp2[id.substr(1,3)].fi++,mp2[id.substr(1,3)].se+=score;
mp3[id.substr(4,6)].pb({id,score});
}
int kase=1;
while(m--)
{
int t;
cin>>t;
if(t == 1)
{
char c;
cin>>c;
printf("Case %d: %d %c\n",kase++,t,c);
vector<Node> res;
for(int i=0;i<mp1[c].size();i++)
{
Node j=mp1[c][i];
res.pb(j);
}
sort(res.begin(),res.end());
if(res.size() == 0) puts("NA");
else
{
for(int i=0;i<res.size();i++)
{
Node j=res[i];
printf("%s %d\n",j.id.c_str(),j.score);
}
}
}
else if(t == 2)
{
string site;
cin>>site;
printf("Case %d: %d %s\n",kase++,t,site.c_str());
if(mp2[site].fi == 0) puts("NA");
else
printf("%d %d",mp2[site].fi,mp2[site].se);
}
else
{
string date;
cin>>date;
printf("Case %d: %d %s\n",kase++,t,date.c_str());
unordered_map<string,int> res;
for(int i=0;i<mp3[date].size();i++)
{
Node j=mp3[date][i];
res[j.id.substr(1,3)]++;
}
vector<Node> ans;
for(auto t:res)
ans.pb({t.fi,t.se});
sort(ans.begin(),ans.end());
if(ans.size() == 0) puts("NA");
else
{
for(int i=0;i<ans.size();i++)
{
Node j=ans[i];
printf("%s %d\n",j.id.c_str(),j.score);
}
}
}
}
//system("pause");
return 0;
}