PAT甲级——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 after 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
/*
1.Clarification:
return registration_number final_rank location_number local_rank
so we need struct informations such as number,grade,final_rank,location number,local_rank
and woe use algorithm sort to sort the grade
The time cost is:
*/
#include <iostream>
#include <string>
#include <algorithm>
#include<cstring>
using namespace std;
struct student{
char number[13];
int grade;
int final_rank;
int location_number;
int local_rank;
}stu[31000];
bool cmp(student a,student b){
if(a.grade!=b.grade)
{
return a.grade>b.grade;
}
else
{
return strcmp(a.number,b.number)<0;
}
}
int main()
{
// freopen("C://坚果云//算法//PATA1025in.txt","r",stdin);
// freopen("C://坚果云//算法//PATA1025out.txt","w",stdout);
int N,K,num=0;
scanf("%d",&N);
for(int i=1;i<=N;i++)
{
scanf("%d",&K);
for(int j=0;j<K;j++)
{
scanf("%s %d",&stu[num].number,&stu[num].grade);
stu[num].location_number = i;
num++;
}
sort(stu+num-K,stu+num,cmp);
stu[num-K].local_rank = 1;
for(int t=num-K+1;t<num;t++)
{
if(stu[t].grade!=stu[t-1].grade)
{
stu[t].local_rank=t+1-num+K;
}
else
{
stu[t].local_rank = stu[t-1].local_rank;
}
}
}
sort(stu,stu+num,cmp);
printf("%d\n",num);
int r=1;
for(int i=0;i<num;i++)
{
if(i>0&&stu[i].grade!=stu[i-1].grade)
{
r=i+1;
}
printf("%s ",stu[i].number);
printf("%d %d %d\n",r,stu[i].location_number,stu[i].local_rank);
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
PAT甲级——1025 PAT Ranking的更多相关文章
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT 甲级 1025.PAT Ranking C++/Java
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Z ...
- PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)
题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...
- 【PAT】1025. PAT Ranking (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...
- PAT 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- PAT甲级——A1025 PAT Ranking
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- PAT甲级1075 PAT Judge
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032 题意: 有m次OJ提交记录,总共有k道 ...
- PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)
1075 PAT Judge (25分) The ranklist of PAT is generated from the status list, which shows the scores ...
- PAT甲级——A1075 PAT Judge
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
随机推荐
- UVA - 10285 Longest Run on a Snowboard(最长的滑雪路径)(dp---记忆化搜索)
题意:在一个R*C(R, C<=100)的整数矩阵上找一条高度严格递减的最长路.起点任意,但每次只能沿着上下左右4个方向之一走一格,并且不能走出矩阵外.矩阵中的数均为0~100. 分析:dp[x ...
- UVM实战[一]
一个新的连载系列,将以一个实际的UVM环境代码讲解的使用.机制等,更新周期会比较长. 文件说明 分享的文件是我个人和同学在参加复微杯大学生电子设计大赛中所完成的设计.赛题来自数字命题AI赛道,有兴趣可 ...
- nodejs(10)express路由
后端路由 前端请求的URL地址,都要对应一个后端的处理函数,那么 这种URL地址到 处理函数之间的对应关系,就叫做后端路由: 在Express中,路由的主要职责 就是 把客户端的请求,分发到对应的处理 ...
- MySQL-TPS,QPS到底是什么
计算TPS,QPS的方式 qps,tps是衡量数据库性能的关键指标,网上普遍有两种计算方式 TPS,QPS相关概念 QPS:Queries Per Second 查询量/秒,是一台服务 ...
- ssh首次链接出现yes/no提示和ansible提示
修改文件: /etc/ssh/ssh_config 在文件中添加如下信息:StrictHostKeyChecking no 改本机的/etc/ssh/ssh_config文件中的"# Str ...
- IO流的学习以及统计次数最多的单词
IO流: 处理数据类型:字节流(InputStream OutputStream)和字节流(Reader Writer) 数据流向不同:输入流和输出流(FileInputStream File ...
- 洛谷 P1060开心的金明
题目描述 金明今天很开心,家里购置的新房就要领钥匙了,新房里有一间他自己专用的很宽敞的房间.更让他高兴的是,妈妈昨天对他说:“你的房间需要购买哪些物品,怎么布置,你说了算,只要不超过NN元钱就行”.今 ...
- 深入分析Java反射(五)-类实例化和类加载
前提 其实在前面写过的<深入分析Java反射(一)-核心类库和方法>已经介绍过通过类名或者java.lang.Class实例去实例化一个对象,在<浅析Java中的资源加载>中也 ...
- HDU-3038 How Many Answers Are Wrong(带权并查集区间合并)
http://acm.hdu.edu.cn/showproblem.php?pid=3038 大致题意: 有一个区间[0,n],然后会给出你m个区间和,每次给出a,b,v,表示区间[a,b]的区间和为 ...
- WebAPI异常捕捉处理,结合log4net日志(webapi框架)
一:异常捕捉处理 首先,在我们需要区分controller的类型.是全部基层controller,还是Apicontroller.(当然一般API框架,用的都是Apicontroller).两者异常处 ...