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 ...
随机推荐
- webpack前端简单配置
每次用webpack创建项目时,总是要安装一堆包,还要配置一系列文件解析规则,webpack打包规则等,烦不胜烦.网上找的很多webpack配置里面很多里面的配置或者引入包都是被弃用的,因此自己总结了 ...
- LiteByte教程
转载请标明原文地址:https://www.cnblogs.com/zhangyukof/p/12073041.html 简介 LiteByte是一种轻量级的二进制数据交换格式.体积小巧.简单易用是设 ...
- Internet History,Technology,and Security -Technology: Application Protocols(Week7)
Week7 Technology: Application Protocols This week, we’ll be covering application protocols. With rel ...
- CouchDB学习-介绍
官方文档 CouchDB 1文档存储 CouchDB服务器主机是一个存储文档的数据库.每一个文档在数据库中都有唯一的名字.CouchDB提供RESTful HTTP API用来读取和更新(添加,编辑, ...
- CURL命令学习三
-I 只获取请求头 -k --insecure 每次SSL连接curl都需要验证是否安全.-k参数表示如果不安全也可以继续操作. -4 --ipv4 告诉curl只使用ipv4地址 -6 --ipv6 ...
- 因特尔CPU上TM和R标识的区别
TM是英文trademark的缩写,TM标志并非对商标起到保护作用,它与R不同,TM表示的是该商标已经向国家商标局提出申请,并且国家商标局也已经下发了<受理通知书>,进入了异议期,这样就可 ...
- RF之简介
robot framework 是一个通用型的自动测试框架 - 自动测试用例的实现方式 - 自动测试用例的开发支持 : IDE.库 - 和用例管理系统的集成 - 测试执行:相关测试套件和测试用例的执 ...
- python字符串与字典转换
经常会遇到字典样式字符串的处理,这里做一下记录. load load针对的是文件,即将文件内的json内容转换为dict import json test_json = json.load(open( ...
- Appium 使用笔记
零.背景 公司最近有个爬虫的项目,先拿小红书下手,但是小红书很多内容 web 端没有,只能用 app 爬,于是了解到 Appium 这个强大的框架,即可以做自动化测试,也可以用来当自动化爬虫. 本文的 ...
- 洛谷P5364 [SNOI2017]礼物 题解
传送门 /* 热情好客的小猴子请森林中的朋友们吃饭,他的朋友被编号为 1∼N,每个到来的朋友都会带给他一些礼物:大香蕉.其中,第一个朋友会带给他 11 个大香蕉,之后,每一个朋友到来以后,都会带给他之 ...