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 ;
}

1025 PAT Ranking 双重排序的更多相关文章

  1. 1025 PAT Ranking[排序][一般]

    1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...

  2. PAT甲题题解-1025. PAT Ranking (25)-排序

    排序,求整体的排名和局部的排名整体排序,for循环一遍同时存储整体目前的排名和所在局部的排名即可 #include <iostream> #include <cstdio> # ...

  3. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

  4. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  5. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  6. PAT甲级——1025 PAT Ranking

    1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  7. PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)

    题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...

  8. 【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)

    题意: 输入一个正整数N(N<=100),表示接下来有N组数据.每组数据先输入一个正整数M(M<=300),表示有300名考生,接下来M行每行输入一个考生的ID和分数,ID由13位整数组成 ...

  9. 【PAT】1025. PAT Ranking (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...

随机推荐

  1. exports、module.exports 和 export、export default

    先了解他们的使用范围. require: node 和 es6 都支持的引入export / import : 只有es6 支持的导出引入module.exports / exports: 只有 no ...

  2. mysql中where和having子句的区别和具体用法

    1.mysql中的where和having子句的区别 having的用法 having字句可以让我们筛选成组后的各种数据,where字句在聚合前先筛选记录,也就是说作用在group by和having ...

  3. android开发针对小米、三星、华为8.0+系统个别型号打开应用闪退

    最近开发中有个别客户反馈新换的三星.小米或者华为手机打开应用就闪退,而且是个别型号.针对这种情况特别查阅了一些资料,原因是8.0+系统的手机不允许后台创建服务,那么怎么修改呢,请看代码: 1.修改启动 ...

  4. JVM 学习笔记一 :JVM类加载机制

    前言: 最近在看JVM相关资料,这里记录下学习笔记,希望自己能坚持学完,打牢基础.   一.类加载过程 1,类从被加载到JVM中开始,到卸载为止,整个生命周期包括:加载.验证.准备.解析.初始化.使用 ...

  5. python同步IO编程——StringIO、BytesIO和stream position

    主要介绍python两个内存读写IO:StringIO和BytesIO,使得读写文件具有一致的接口 StringIO 内存中读写str.需要导入StringIO >>> from i ...

  6. 安卓AlertDialog四种对话框的最科学编写用法

    首先我们上图: xml的代码如下,用于编写按钮: <?xml version="1.0" encoding="utf-8"?> <Linear ...

  7. SpannableStringBuilder实现图文混排

    1.我的后面添加图片 ssb = new SpannableStringBuilder("我的后面添加图片: "); ssb.setSpan(, , Spannable.SPAN_ ...

  8. 轻松玩转windows之redis实战

    Redis是一个常用的键值对数据库.本篇分享一下如何轻松在睿江云上实现基于windows的redis开发环境. 1. 登录睿江云 点击右上角登录框 ​ 进入登录页面,输入账号密码登录 ​ 进入控制台, ...

  9. centos7 nginx 配置

    1.下载nginx 官方下载1.6.2 2.编译安装 [root@bogon nginx-1.6.2]# ./configure --prefix=/usr/local/webserver/nginx ...

  10. 安全性测试:OWASP ZAP 2.8 使用指南(四):ZAP扫描移动应用安全

    在做移动应用(APP,小程序等)测试时,需要关注应用安全性. ZAP是可以用来进行手机移动应用渗透性测试扫描的. 正因为ZAP是采用“中间代理”的形式,截取并扫描所有客户端与服务器的交互请求,作为客户 ...