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 ...
随机推荐
- STL学习顺序
仅供参考,大家要学会自己制作,很有成就感的啊! 先看<c++标准程序库>这本书很厚,但是其实很简单,然后再看effective stl,注意顺序,我初学的时候stl还没了解多少就看effe ...
- HTTP协议(一):概述
背景介绍 但凡世界上牛逼的人物,都会有一个非常离奇的经历.比如说乞丐出身的皇帝朱元璋,出生时家中红光大作,映红了半边天;再比如说无良皇帝刘邦,简直不要太牛逼,说自己是老妈和一条白龙交合生出的自己,而老 ...
- html_js
<!-- js的特点:别名脚本 -由浏览器内置的JavaScript引擎执行代码. -解析执行:事先不编译,逐行执行 -面向对象:内置大量的现成对象 适宜: -客户端的数据计算:不需要保存和提交 ...
- JS-语句二
for循环的4个要素: 1.初始值 2.条件判断 3.状态改变 4.循环体 for循环的写法: for(var i=0;i>10;i++) ...
- git本地仓库连接同步修改远程仓库
如何使用GIT BASH同步远程仓库 1. 新建一个目录 2. 右键GIT BASH 3. git clone git@github.com:purity12138/221701117.git (SS ...
- 云服务器Linux版本下---安装git
xshell进入云服务器: 按照git官网:https://git-scm.com/download/linux 的教程输入: apt-get install git 本地没有包????? 原来是 ...
- vSphere 6.7 新特性 — 基于虚拟化的安全 (VBS)
https://blogs.vmware.com/china/2018/07/27/vsphere-6-7-%E6%96%B0%E7%89%B9%E6%80%A7-%E5%9F%BA%E4%BA%8E ...
- qt使用了qstackedwidget里面放置了widget后对该子widget设置的样式无效
关键字:子窗口样式无效 QStackedwidget 问题: 我有一个对话框,里面放了一个qstackedwidget,qstackedwidget放了N个子窗口,使用addwidget添加上去了: ...
- 18. docker 容器部署 python-redis
1. 编写 Vagrantfile 并创建虚拟机 并虚拟机绑定外部 192.168.205.10:8888 ip:port # -*- mode: ruby -*- # vi: set ft=ruby ...
- VC调用VB写的COM
VB. 步骤: 1.创建类库:类库的创建必须分为接口和实现类:给外面提供的是COM接口: 创建了接口和类之后还要创建"Guid",这个在"工具->创建GUID&qu ...