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 ...
随机推荐
- [转]Linux命令行上传文件到 百度网盘 bypy
安装软件工具: apt-get install python-pip pip install requests pip install bypy 授权登陆: 执行 bypy info,显示下边信息,根 ...
- CNN:转置卷积输出分辨率计算
上一篇介绍了卷积的输出分辨率计算,现在这一篇就来写下转置卷积的分辨率计算.转置卷积(Transposed convolution),转置卷积也有叫反卷积(deconvolution)或者fractio ...
- Java自学-集合框架 聚合操作
聚合操作 步骤 1 : 聚合操作 JDK8之后,引入了对集合的聚合操作,可以非常容易的遍历,筛选,比较集合中的元素. 像这样: String name =heros .stream() .sorted ...
- 主席树--动态区间第k小
主席树--动态区间第\(k\)小 模板题在这里洛谷2617. 先对几个问题做一个总结: 阅读本文需要有主席树的基础,也就是通过区间kth的模板题. 静态整体kth: sort一下找第k小,时间复杂度\ ...
- 多种类型SQL注入
前言 发现MYSQL手注注入方式用得多了,几乎都快忘记其它数据库注入的方式了,这里不讲绕过姿势和写shell,毕竟网上很多前辈都给了方法,我只讲一些基本的注入方式(只是记录一下各自的特性,记下来方便以 ...
- POJ 3660 Cow Contest【Floyd 传递闭包】
传送门:http://poj.org/problem?id=3660 题意:有n头牛, 给你m对关系.(a, b)表示牛a能打败牛b, 求在给出的这些关系下, 能确定多少头牛的排名. 传递闭包: 关系 ...
- Animate.css 一款强大的预设css3动画库
Animate.css是一个有趣的,跨浏览器的css3动画库.很值得我们在项目中引用. 用法 1.首先引入animate css文件 <head> <link rel="s ...
- 清除input表单内容
碰到几次情况,页面刷新或者从上级页面返回表单的内容依然遗留,很影响使用. <form action="" method="" autocomplete=& ...
- 吴裕雄--天生自然Linux操作系统:Linux 磁盘管理
Linux磁盘管理好坏直接关系到整个系统的性能问题. Linux磁盘管理常用三个命令为df.du和fdisk. df:列出文件系统的整体磁盘使用量 du:检查磁盘空间使用量 fdisk:用于磁盘分区 ...
- geodjango七日学习笔记 (7.30整理本地笔记上传到网络)
第一天进行到现在,在开端的尾巴,想起来写一个学习笔记, 开发环境已搭好,用的是pycharm 环境是本机已有的interpreter python3.7 接下来要做的是新建一个geodjango项 ...