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 afer the test. Now it is your job to write a program to correctly merge all the
ranklists and generate the final rank.

Input Specification:

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.

Output Specification:

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.

Sample Input:

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

Sample Output:

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

题目意思:模拟一下PAT考试的排名机制,n个考场,每个考场若干学生,给出每个考场学生的登记编号和考试分数,确定排名,输出所有考生的登记编号、总排名、考场号、考场内排名。这里如果出现了相同的分数,那么登记编号小的优先,但排名确实并列的,假如两个人都是第一名,那么次于他们的那个人将会是第三名。

解题思路:先在本考场内排名,记录在本考场内的名次,再到总的当中排名,记录最终的排名。

/*
双重排序
*/
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
struct stu
{
string id;
int score;
int final_rank;//最终排名
int local;//所在考场号
int local_rank;//考场内排名
};
stu a[*];
int my_cmp(stu a,stu b)
{
if(a.score != b.score)
{
return a.score > b.score;
}
else//成绩相同,考号小的靠前
{
return a.id < b.id;
}
}
int main()
{ int n,m;
int i,j;
int cnt=;
cin>>n;
for(i=; i<=n; i++)
{
cin>>m;
for(j=; j<m; j++)
{
cin>>a[cnt].id>>a[cnt].score;
a[cnt].local=i;//所在考场
cnt++;
}
sort(a+cnt-m,a+cnt,my_cmp);//此考场学生下标为[cnt-k,cnt-1]
int loc_rank=;
int pre=a[cnt-m].score;
for(j = cnt - m; j < cnt; j++)
{
if(a[j].score != pre)//与前一个同分
{
loc_rank = j-(cnt-m) + ;
pre = a[j].score;
}
a[j].local_rank = loc_rank;
}
}
cout << cnt << endl;
sort(a,a+cnt,my_cmp);
int fin_rank=;
int pre=a[].score;
for(j = ; j < cnt; j++)
{
if(a[j].score != pre)//与前一个同分
{
fin_rank = j + ;
pre = a[j].score;
}
a[j].final_rank = fin_rank;
cout<< a[j].id <<' '<< a[j].final_rank <<' '<< a[j].local <<' '<< a[j].local_rank <<endl;
}
return ;
}

最新文章

  1. Linux基础介绍【第五篇】
  2. Ideas about the future of management
  3. .NET开源项目
  4. Linux内核原子(1) - spinlock的实现
  5. openssh for windows安装
  6. BeagleBone Black&ndash; 智能家居控制系统 LAS - ESP8266 UDP 服务
  7. js调用百度地图API创建地图,搜索位置
  8. keystone系列二:keystone源码分析
  9. WOJ 124. Football Coach 网络流
  10. html详解(二)
  11. linux查找并替换命令
  12. nc6 用业务插件注册来跑按钮事件
  13. 前台获取json未定义问题之两种常用解决办法
  14. [java] 求2个集合的交 差 并集
  15. Jenkins 执行python脚本
  16. MySql错误处理(三)- 错误处理的例子
  17. 解决jar格式文件,双击不能直接运行问题
  18. INSTEAD OF与AFTER触发器
  19. jquery库实现iframe自适应内容高度和宽度
  20. java事务(一)

热门文章

  1. 《一头扎进》系列之Python+Selenium框架设计篇4- 价值好几K的框架,呵!这个框架有点意思啊
  2. contiue和break的用法
  3. Spring Cloud Config入门(本地配置)
  4. 解决zabbix监控因php问题导致图形界面中文乱码方法
  5. python基础知识第九篇(函数)
  6. c++之基础知识
  7. Python爬虫实战:批量下载网站图片
  8. 关于独显A卡利用率一直是0不运行的问题
  9. WebMvcConfigurationSupport 避坑指南
  10. CAD怎么算面积?这种方法你要知道