AcWing 1647. 解码PAT准考证
原题链接
简单
作者:
jjkstra
,
2020-07-11 15:58:00
,
所有人可见
,
阅读 656
C++ 代码
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;
struct testee
{
string num;
int grade;
bool operator<(testee &a)
{
if (a.grade == grade)
return num < a.num;
return grade > a.grade;
}
};
int main()
{
int n, m;
cin >> n >> m;
vector<testee> v(n);
for (int i = 0; i < n; i++)
cin >> v[i].num >> v[i].grade;
for (int i = 1; i <= m; i++)
{
int type;
string term;
cin >> type >> term;
printf("Case %d: %d %s\n", i, type, term.c_str());
vector<testee> ans;
if (type == 1)
{
for (auto res : v)
if (res.num[0] == term[0])
ans.push_back(res);
}
if (type == 2)
{
int cnt = 0, total = 0;
for (auto res : v)
if (res.num.substr(1, 3) == term)
cnt++, total += res.grade;
if (cnt == 0)
cout << "NA" << endl;
else
cout << cnt << " " << total << endl;
continue;
}
if (type == 3)
{
unordered_map<string, int> map;
for (auto res : v)
if (res.num.substr(4, 6) == term)
map[res.num.substr(1, 3)]++;
for (auto it : map)
ans.push_back({it.first, it.second});
}
sort(ans.begin(), ans.end());
for (auto res : ans)
printf("%s %d\n", res.num.c_str(), res.grade);
if (ans.size() == 0)
cout << "NA" << endl;
}
return 0;
}