AcWing 1647. 解码PAT准考证(暴躁写法)
原题链接
简单
作者:
Value
,
2020-05-31 13:02:26
,
所有人可见
,
阅读 813
#include <iostream>
#include <algorithm>
#include <cstring>
#include <map>
using namespace std;
const int N = 1E4 + 10;
typedef pair<int, int> pii;
struct node{
string id;
int score;
};
node stu[N];
int n, m;
int way;
bool cmp(node a, node b){
if(a.score != b.score) return a.score > b.score;
else return a.id < b.id;
}
bool cmp1(pii a, pii b){
if(a.second != b.second) return a.second > b.second;
else return a.first < b.first;
}
int main(){
cin >> n >> m;
for(int i = 0; i < n; i ++ ) cin >> stu[i].id >> stu[i].score;
for(int i = 1; i <= m; i ++ ){
cin >> way;
printf("Case %d: %d ", i, way);
switch(way){
case 1 :{
char rank; cin >> rank;
cout << rank << endl;
vector<node> fit;
for(int i = 0; i < n; i ++ ){
if(stu[i].id[0] == rank) fit.push_back(stu[i]);
}
sort(fit.begin(), fit.end(), cmp);
if(fit.size() == 0) cout << "NA" << endl;
else for(auto student : fit) cout << student.id << " " << student.score << endl;
break;
}
case 2 :{
int room; cin >> room;
cout << room << endl;
int num, sum; num = sum = 0;
for(int i = 0; i < n; i ++ ){
int r = (stu[i].id[1] - '0') * 100 + (stu[i].id[2] - '0') * 10 + (stu[i].id[3] - '0');
if(room == r) {sum += stu[i].score, num ++ ;}
}
if(num == 0) cout << "NA" << endl;
else cout << num << " " << sum << endl;
break;
}
case 3 :{
string date; cin >> date;
cout << date << endl;
map<int, int> fit;
for(int i = 0; i < n; i ++ ){
string d = stu[i].id.substr(4, 6);
// cout << d << endl;
if(d == date){
int r = (stu[i].id[1] - '0') * 100 + (stu[i].id[2] - '0') * 10 + (stu[i].id[3] - '0');
fit[r] ++ ;
}
}
vector<pii> res;
for(auto it : fit) res.push_back({it.first, it.second});
sort(res.begin(), res.end(), cmp1);
if(res.size() == 0) cout << "NA" << endl;
else for(auto student : res) cout << student.first << " " << student.second << endl;
break;
}
}
}
return 0;
}
感觉系统有bug, 一开始这段代码tle, 多交几次即ac了!