1025 PAT Ranking 双重排序
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 双重排序的更多相关文章
- 1025 PAT Ranking[排序][一般]
1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...
- PAT甲题题解-1025. PAT Ranking (25)-排序
排序,求整体的排名和局部的排名整体排序,for循环一遍同时存储整体目前的排名和所在局部的排名即可 #include <iostream> #include <cstdio> # ...
- 1025 PAT Ranking (25分)
1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)
题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...
- 【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)
题意: 输入一个正整数N(N<=100),表示接下来有N组数据.每组数据先输入一个正整数M(M<=300),表示有300名考生,接下来M行每行输入一个考生的ID和分数,ID由13位整数组成 ...
- 【PAT】1025. PAT Ranking (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...
随机推荐
- 我学习Python的经历
1. 被逼无奈找到了Python Python作为当今非常热的话题,常常被各级别的程序员所提到,也有很多的小白问我,到底啥是Python,它能干啥! 我用Python时间不是特别长,最早使用是在201 ...
- CSS3新特性简单总结(持续补充常用到的情景)
1.CSS3边框border-radius 左上右下box-shadow box-shadow: 水平阴影(可负值,必) 垂直阴影(可负值,必) 模糊距离 阴影尺寸 颜色颜色 inset(将外部阴影改 ...
- NodeJS4-1静态资源服务器实战_实现访问获取里面的内容
.gitignore 匹配模式前 / 代表项目根目录 匹配模式最后加 / 代表是目录 匹配模式前加 ! 代表取反 * 代表任意一个字符 ? 匹配任意一个字符 ** 匹配多级目录 统一代码风格配置可以用 ...
- VS2019 开发Django(七)------VS2019不能格式化html代码
如题,在VS2019中不能使用快捷键Ctrl+K,+D格式化html代码,印象中之前的版本是可以的吧!不太确定,这给我带来了很大的麻烦,在编写Django项目的时候,标准的模板是新建的html文件,不 ...
- HttpRunner学习5--使用variables声明变量
前言 在HttpRunner中,如果需要声明变量,可以通过关键字 variables 来完成,要引用声明的变量,则是通过 $+变量名 (如 $token )来实现.variables 可以在 conf ...
- try catch在for循环外面还是里面
static void Main(string[] args) { //将异常写在循环外,出现异常循环终止 try { Console.WriteLine("抛出异常不输出"); ...
- JDK1.8 中的HashMap
HashMap本质上Java中的一种数据结构,他是由数组+链表的形式组织而成的,当然了在jdk1.8后,当链表长度大于8的时候为了快速寻址,将链表修改成了红黑树. 既然本质上是一个数组,那我们 ...
- 2019年创意可爱卡通小清新教育课件培训PPT模板
模版来源:http://ppt.dede58.com/jiaoxuekejian/26791.html
- Ligg.WinOa-000: Windows运维自动化编程实战--前言
本开源项目Ligg.WinOa是一个基于Ligg.EasyWinApp的Windows运维自动化应用.通过Ligg.EasyWinForm生成2个功能界面:管理员工具箱和用户工具箱:通过Lig ...
- JS---课程介绍 + JavaScript分三个部分
Web API---课程介绍 DOM: 概念-----能够说出来--理解 作用----记住了----后来理解 回顾JS分几个部分---知道 DOM树---能够说出 ...