PAT 准考证号由 4 部分组成:
现给定一系列考生的准考证号和他们的成绩,请你按照要求输出各种统计信息。 输入格式:输入首先在一行中给出两个正整数 N(≤104)和 M(≤100),分别为考生人数和统计要求的个数。 接下来 N 行,每行给出一个考生的准考证号和其分数(在区间 [0,100] 内的整数),其间以空格分隔。 考生信息之后,再给出 M 行,每行给出一个统计要求,格式为:
输出格式:对每项统计要求,首先在一行中输出
如果查询结果为空,则输出 |
输入样例:
8 4
B123180908127 99
B102180908003 86
A112180318002 98
T107150310127 62
A107180908108 100
T123180908010 78
B112160918035 88
A107180908021 98
1 A
2 107
3 180908
2 999
输出样例:
Case 1: 1 A
A107180908108 100
A107180908021 98
A112180318002 98
Case 2: 2 107
3 260
Case 3: 3 180908
107 2
123 2
102 1
Case 4: 2 999
NA
考察 : 信息较复杂逻辑处理与排序 |
注意 : 查询3日期的输出有前置0 |
思路 : map+map+map....... |
C/C++
#include<bits/stdc++.h>
using namespace std;
void input(int command); // 查询操作
vector<pair<string,int>> top[3]; // 各个级别储存 0-T,1-A,2-B
map<int,pair<long,long>> room; // 考场号 -> 考场人数 and 总得分
map<long,vector<int>> findRoom; // 日期 -> 该日期拥有的考场号
map<pair<long,int>,int> findNum; // 日期+考场号 -> 当天该考场人数
bool cmp(const pair<string,int>& x,const pair<string,int>& y){ // 排序PAB各个级别的排名
if(x.second!=y.second) return x.second>y.second;
return x.first < y.first;
}
bool cmp1(pair<int,int> x,pair<int,int> y){ // 排序查询3操作
if(x.second!=y.second) return x.second>y.second;
return x.first < y.first;
}
int main()
{
string id;
int N,M,n,roomId;
cin >> N >> M;
while (N--){
cin >> id >> n;
// 查询1 录入
if(id[0]=='T') top[0].emplace_back(id,n);
else if(id[0]=='A') top[1].emplace_back(id,n);
else top[2].emplace_back(id,n);
// 查询2 录入
roomId = (id[1]-48)*100+(id[2]-48)*10+id[3]-48;
room[roomId].first++;
room[roomId].second+=n;
// 查询3 录入
long day = 0;
for(int z=4;z<10;z++) day = day*10+id[z]-48;
if(0==findNum[pair<long,int>(day,roomId)]++) findRoom[day].push_back(roomId);
}
for(auto & z : top) sort(z.begin(),z.end(),cmp);
for(int z=1;z<=M;z++){
cout << "Case " << z << ": ";
cin >> n;
input(n);
}
return 0;
}
void input(int command)
{
long day; // 数据读入使用
char level; // 数据读入使用
bool flag = true; // 判断有无输出
if(command==1)
{
cin >> level; cout << command << " " << level << endl;
day = level=='T'? 0 : level=='A'? 1 : 2;
for(const auto& x:top[day]) cout << x.first << " " << x.second << endl;
if(top[day].empty()) flag = false;
}
else if(command==2)
{
cin >> day; cout << command << " " << day << endl;
if(room[day].first>0) cout << room[day].first << " " << room[day].second << endl;
else flag = false;
}
else
{
cin >> day;
printf("%ld %06ld\n",command,day);
vector<pair<int,int>> box;
for(int x:findRoom[day]){
box.emplace_back(x,findNum[pair<long,int>(day,x)]);
}
sort(box.begin(),box.end(),cmp1);
if(box.empty()) flag = false;
else for(auto x:box) cout << x.first << " " << x.second << endl;
}
if(!flag) cout << "NA" << endl;
}