失分点:
- and the output must be sorted in nondecreasing order of their registration numbers. 成绩相同的时候用准考证号码由小到大排序。
a.score != b.score ? a.score > b.score : a.id < b.id;
- registration number (a 13-digit number) 准考证号固定13位,但是当输入为000000011111时存储之后再打印就是11111了,所以要小心。
printf("%013lld %d %d %d\n",stu[i].id.....);
合格代码:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define N 30000
typedef struct Stu{
long long id;
int score;
int final_rank;
int location_number;
int local_rank;
Stu(){
id=0;
score=0;
final_rank=0;
location_number=0;
local_rank=0;
}
}Stu;
int locations=0;
int length[N]={0};
bool cmp(Stu a,Stu b){
return a.score != b.score ? a.score > b.score : a.id < b.id;
}
int main(){
// freopen("test.txt","r+",stdin);
scanf("%d",&locations);
int i,j;
vector<Stu>stu;
for(i=0;i<locations;i++){
scanf("%d",&length[i]);
vector<Stu>s;
for(j=0;j<length[i];j++){
Stu v;
scanf("%lld %d",&v.id,&v.score);
v.location_number=i+1;
s.push_back(v);
}
sort(s.begin(),s.end(),cmp);
s[0].local_rank=1;
// s[0].location_number=i+1;
stu.push_back(s[0]);
for(j=1;j<length[i];j++){
s[j].local_rank=((s[j].score==s[j-1].score)?s[j-1].local_rank:j+1);
stu.push_back(s[j]);
}
}
sort(stu.begin(),stu.end(),cmp);
stu[0].final_rank=1;
for(i=1;i<stu.size();i++){
stu[i].final_rank=((stu[i].score==stu[i-1].score)?stu[i-1].final_rank:i+1);
}
cout<<stu.size()<<endl;
for(i=0;i<stu.size();i++){
printf("%013lld %d %d %d\n",stu[i].id,stu[i].final_rank,stu[i].location_number,stu[i].local_rank);
// cout<<stu[i].id<<" "<<stu[i].final_rank<<" "<<stu[i].location_number<<" "<<stu[i].local_rank<<endl;
}
}