Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.
Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.
For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:
registration_number final_rank location_number local_rank
The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.
有 n
个考场,每个考场有若干数量的学生,给出每个考场中考生的编号和分数,要求算排名,输出所有考生的编号、排名、考场号、考场内排名
简单题
ID有类似 000003
这种形式的,如果是数字类型就容易输出错误,前导零别忘了。
#include
#include
int n,k[105],cnt;
struct Student {
long long num;
int score;
int final_rank,location_number,local_rank;
bool operator >(const Student &a)const {
if(score!=a.score) {
return score>a.score;
} else {
return num<a.num;
}
};
} stu[10000005];
using namespace std;
int main() {
cin>>n;
cnt=0;
for(int i=1; i<=n; i++) {
cin>>k[i];
for(int j=1; j<=k[i]; j++) {
cin>>stu[cnt+j].num>>stu[cnt+j].score;
}
sort(stu+cnt+1,stu+cnt+k[i]+1,greater<Student>());
stu[cnt+1].location_number=i;
stu[cnt+1].local_rank=1;
for(int j=2; j<=k[i]; j++) {
if(stu[cnt+j].score==stu[cnt+j-1].score) {
stu[cnt+j].local_rank=stu[cnt+j-1].local_rank;
} else {
stu[cnt+j].local_rank=j;
}
stu[cnt+j].location_number=i;
}
cnt+=k[i];
}
sort(stu+1,stu+cnt+1,greater<Student>());
stu[1].final_rank=1;
for(int i=2; i<=cnt; i++) {
if(stu[i].score==stu[i-1].score) {
stu[i].final_rank=stu[i-1].final_rank;
} else {
stu[i].final_rank=i;
}
}
cout<<cnt<<endl;
// 1234567890005 1 1 1
for(int i=1; i<=cnt; i++) {
cout<<stu[i].num<<" "<<stu[i].final_rank<<" "<<stu[i].location_number<<" "<<stu[i].local_rank<<endl;
}
return 0;
}
#include
#include
#include
int n,k[105],cnt;
struct Student {
long long num;
int score;
int final_rank,location_number,local_rank;
bool operator >(const Student &a)const {
if(score!=a.score) {
return score>a.score;
} else {
return num<a.num;
}
};
} stu[10000005];
using namespace std;
int main() {
cin>>n;
cnt=0;
for(int i=1; i<=n; i++) {
cin>>k[i];
for(int j=1; j<=k[i]; j++) {
cin>>stu[cnt+j].num>>stu[cnt+j].score;
}
sort(stu+cnt+1,stu+cnt+k[i]+1,greater<Student>());
stu[cnt+1].location_number=i;
stu[cnt+1].local_rank=1;
for(int j=2; j<=k[i]; j++) {
if(stu[cnt+j].score==stu[cnt+j-1].score) {
stu[cnt+j].local_rank=stu[cnt+j-1].local_rank;
} else {
stu[cnt+j].local_rank=j;
}
stu[cnt+j].location_number=i;
}
cnt+=k[i];
}
sort(stu+1,stu+cnt+1,greater<Student>());
stu[1].final_rank=1;
for(int i=2; i<=cnt; i++) {
if(stu[i].score==stu[i-1].score) {
stu[i].final_rank=stu[i-1].final_rank;
} else {
stu[i].final_rank=i;
}
}
cout<<cnt<<endl;
for(int i=1; i<=cnt; i++) {
cout<<setfill('0')<<setw(13)<<stu[i].num<<" "<<stu[i].final_rank<<" "<<stu[i].location_number<<" "<<stu[i].local_rank<<endl;
}
return 0;
}