pat1025. PAT Ranking (25)
1025. PAT Ranking (25)
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
string的相互比较:
#include<string>
#include<iostream>
using namespace std;
int main(){
//freopen("D:\\input.txt","r",stdin);
//a.compare(b)
//a>b 1
//a==b 0
//a<b -1
string a="",b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
a="";
b="";
cout<<a.compare(b)<<endl;
return ;
}
比较的思想:
1.整体排序,注意成绩非升序(成绩相同时,编号升序)。
2.
localrank[i]:第i个区域当前的排名,允许成绩相同排名相同。
lastgrade[i]:第i个区域前一个排名的成绩。
localnum[i]:第i个区域已经排名的人数。
#include<set>
#include<map>
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cmath>
using namespace std;
int localrank[],lastgrade[],localnum[];
//registration_number final_rank location_number local_rank
struct person{
string s;
int grade,localnum;
};
person per[];
bool cmp(person a,person b){
if(a.grade==b.grade){
return a.s.compare(b.s)<;
}
return a.grade>b.grade;
}
int main(){
//freopen("D:\\input.txt","r",stdin);
int n;
scanf("%d",&n);
int i,j,k,l;
per[].grade=;//哨兵
l=;
for(i=;i<=n;i++){
scanf("%d",&k);
for(j=;j<=k;j++){
cin>>per[l].s;
scanf("%d",&per[l].grade);
per[l++].localnum=i;
}
lastgrade[i]=;
}
l--;
sort(per,per+l+,cmp);
memset(localrank,,sizeof(localrank));
memset(localnum,,sizeof(localnum));
int rank;
cout<<l<<endl;
for(i=;i<=l;i++){
cout<<per[i].s<<" ";
if(per[i].grade<per[i-].grade){
rank=i;
}
cout<<rank<<" "<<per[i].localnum<<" ";
localnum[per[i].localnum]++;
if(per[i].grade<lastgrade[per[i].localnum]){
lastgrade[per[i].localnum]=per[i].grade;
localrank[per[i].localnum]=localnum[per[i].localnum];
}
cout<<localrank[per[i].localnum]<<endl;
}
return ;
}
pat1025. PAT Ranking (25)的更多相关文章
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
- 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 (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...
- 1025. PAT Ranking (25)
题目如下: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology ...
- 1025 PAT Ranking (25)(25 point(s))
problem Programming Ability Test (PAT) is organized by the College of Computer Science and Technolog ...
- PAT A1025 PAT Ranking(25)
题目描述 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...
- 1025 PAT Ranking (25 分)
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- 1025 PAT Ranking (25分) 思路分析 +满分代码
题目 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of ...
随机推荐
- unity list循环
复制的感觉挺有用就保存下来 using System.Collections;using System.Collections.Generic;using UnityEngine; public cl ...
- javascript 获取标签内的内容
js 获取标签内的内容 参考:这篇博客给了我很大的启发. http://www.cnblogs.com/breakdown/archive/2012/10/09/2716221.html 我遇到的问题 ...
- Django之后台管理二
前面讲到admin界面用户的注册以及修改,如果我们注册的用户密码忘记了该怎么办呢 在终端输入如下的命令进行重置 D:\django_test2>python manage.py shell Py ...
- A - Chips
Gerald plays the following game. He has a checkered field of size n × n cells, where m various cells ...
- 转载黑客是如何黑到你手机的?绝对涨姿势,一位黑客的Wi-Fi入侵实录!
声明:这是一虚构的故事,因此对图片均进行了模糊化处理.内容整理自网络! 故事的主人公小黑是一名从事IT相关工作的技术宅男.五一长假来临,宅在家中的他相当无聊,打开手机上的Wi-Fi模块,发现附 ...
- echarts图标legend全选功能添加
平时做图表的时候经常用echarts,确实是一款很好用的插件. 开发中遇到了一个问题,在展示的曲线,也就是legend很多的时候,不太好只展示其中几条.配置中是可以默认设置初始化是否展示,但不适用于全 ...
- [转]关于TDD、BDD和DDD的一些看法
在实际的项目中,我们可能随时面对各种不同的需求,它的各个方面的要素决定了我们所采用的开发模式. 比如,它的复杂度如何?所有的需求是否足够清晰?开发人员对相关的业务是否足够了解?项目的工期是否合理?种种 ...
- 轻量级编辑器透彻指南--Notepad++
Notepad++是Windows环境下的一款编辑器.比起VSCode等现代编辑器,Notepad++同样具备很多功能.Notepad++一个特点就是轻巧,方便在Windows环境中使用,且编辑功能强 ...
- PHP删除目录下的空目录
function rm_empty_dir($path){ if(is_dir($path) && ($handle = opendir($path))!==false){ ...
- IDEA总是启动不了
时常怎么都打不开这个软件,或者很久很久才打开. 解决办法:在任务管理器将IDEA结束进程,再去打开软件,就可以了.