题目描述

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.

输入样例

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85

输出样例

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4

全部AC

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
//p115
using namespace std; const int maxn = 30010; struct Student {
char registration_number[20]; //考生id
int score; //考生成绩
int final_rank; //最终排名
int location_number; //考室号
int local_rank; //考室排名
}stu[maxn]; bool cmp(Student A, Student B) {
if(A.score != B.score) return A.score > B.score; //AB成绩不同,按成绩从大到小排序
else if(A.score == B.score) return strcmp(A.registration_number, B.registration_number) < 0; //AB成绩相同,则按照准考证从小到大排序
} int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE}
int N; //考室数量
scanf("%d", &N);
int a = 0; //初始化考生存储位置
for(int i = 0; i < N; i++) {
int K; //考室中考生的数量
scanf("%d", &K);
//输入各个考室考生的注册号和成绩
for(int j = 0; j < K; j++) {
stu[a].location_number = i + 1;
scanf("%s %d", stu[a].registration_number, &stu[a].score);
a++;
}
}
//初始化每个教室排名
int lrank[N+1] = {0};
int lrealrank[N+1] = {0};
//memset(lrank, 1, N+1);
//按考生成绩从大到小排序
sort(stu, stu+a, cmp);
int rank = 1; //总排名
for(int i = 0; i < a; i++) {
//printf("registration_number:%s location_number:%d score:%d \n", stu[i].registration_number, stu[i].location_number, stu[i].score);
//总排名
if(i == 0) stu[i].final_rank = rank;
else if(i != 0 && stu[i].score == stu[i-1].score) stu[i].final_rank = stu[i-1].final_rank;
else if(stu[i].score < stu[i-1].score) stu[i].final_rank = ++rank;
rank = i+1; //更新总排名
//教室排名
if(i != 0 && stu[i].score == stu[i-1].score && stu[i].location_number == stu[i-1].location_number) { //在同个教室中分数相同
stu[i].local_rank = stu[i-1].local_rank;
lrealrank[stu[i].location_number]++;
} else {
stu[i].local_rank = lrank[stu[i].location_number]; //在同个教室中分数不相同
lrank[stu[i].location_number]++;
lrealrank[stu[i].location_number]++;
}
lrank[stu[i].location_number] = lrealrank[stu[i].location_number];
}
printf("%d\n", a);
for(int i = 0; i < a; i++) {
printf("%s %d %d %d\n", stu[i].registration_number, stu[i].final_rank, stu[i].location_number, stu[i].local_rank+1);
}
return 0;
}

最新文章

  1. Android常用组件之AutoCompleteTextView
  2. Netty : writeAndFlush的线程安全及并发问题
  3. python第十七天-----Django初体验
  4. UI界面的一些简单控件
  5. MySQL(六) —— 自定义函数
  6. TreeSet介绍
  7. iOS中通知中心NSNotificationCenter应用总结
  8. MongoDB - The mongo Shell, Write Scripts for the mongo Shell
  9. 《浅析各类DDoS攻击放大技术》
  10. JavaScript基本概念(一) v0.5
  11. C#读取Excel几种方法的体会
  12. C# DateTime显示时间格式的使用
  13. iOS菜鸟之FMDB的二次封装简单易用
  14. ReportViewer2010冻结行列
  15. Geodatabase - 打开数据库(工作空间)
  16. uva 140
  17. Mac OS X于Android Kernel下载方法
  18. sqlite语句主页
  19. FLIR 相机采集程序
  20. POI操作excle

热门文章

  1. SecureCRT的安装与破解,详细过程
  2. spring事务之事务传播机制和隔离级别
  3. centernet 相关
  4. python 列表切片之负数的含义代码示例
  5. ./与sh区别
  6. redis的哨兵
  7. js判断是否联网
  8. 【转载】Python tips: 什么是*args和**kwargs?
  9. C#剪切生成高质量缩放图片
  10. Java同步数据结构之Collection-Queue