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 ...
 
随机推荐
- JSP注册登录页教程
			
转载请标明原文地址:http://www.cnblogs.com/zhangyukof/p/6785258.html 一.准备工作 已搭建好的SSH框架工程一个,如果没有,请参考我的上一篇文章< ...
 - html5 websocket 示例,websocket在线聊天,php websocket实例
			
WebSocket在线测试工具 http://ws.douqq.com/ 1.连接格式为 ws://IP/域名:端口(示例ws://119.29.3.36:5354) 2.对于内网的测试环境,只需填入 ...
 - 《Java基础知识》Java变量的声明、初始化和作用域
			
一.Java变量的声明 在 Java 程序设计中,每个声明的变量都必须分配一个类型.声明一个变量时,应该先声明变量的类型,随后再声明变量的名字.下面演示了变量的声明方式. double salary; ...
 - 微服务架构 SpringBoot(一)
			
spring Boot:官网地址 https://spring.io/ 由来: 随着spring组件功能的强大,配置文件也越来越复杂繁琐,背离了spring公司的简洁快速开发原理,2015年就推出Sp ...
 - Nginx安装(我觉得我这篇可能是全网最清晰的一篇安装步骤了)
			
原文内容来自于LZ(楼主)的印象笔记,如出现排版异常或图片丢失等问题,可查看当前链接:https://app.yinxiang.com/shard/s17/nl/19391737/46aadb8f-5 ...
 - Activiti架构分析及源码详解
			
目录 Activiti架构分析及源码详解 引言 一.Activiti设计解析-架构&领域模型 1.1 架构 1.2 领域模型 二.Activiti设计解析-PVM执行树 2.1 核心理念 2. ...
 - 【每天一题】LeetCode 121. 买卖股票的最佳时机
			
开源地址:点击该链接 题目描述 * https://leetcode-cn.com/problems/best-time-to-buy-and-sell-stock * 题目描述: * 给定一个数组, ...
 - Paper | MFQE 2.0: A New Approach for Multi-frame Quality Enhancement on Compressed Video
			
目录 1. 要点 2. 压缩视频特性分析 2.1 质量波动 2.2 帧间相关性 3. 方法 3.1 分类器 3.2 好帧运动补偿 3.3 质量增强网络 4. 实验 4.1 差帧质量提升效果 4.2 总 ...
 - LINUX OS EXERCISE 08
			
1 配置crontab计划任务时,记录的格式是什么? 分钟 小时 日期 月份 星期 可执行语句 2 配置crontab计划任务实例. 以root用户身份添加计划任务,每天早上7:30启动sshd服务, ...
 - Vue之循环遍历Json数据,填充Table表格
			
简单记一次Vue循环遍历Json数据,然后填充到Table表格中,展示到前端的代码: async getData(id) { const res = await this.$store.api.new ...