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 ...
随机推荐
- C#泛型理解(一)
一.什么是泛型 泛型是C#语言和公共语言运行库(CLR)中的一个新功能,它将类型参数的概念引入.NET Framework.类型参数使得设计某些类和方法成为可能,例如,通过使用泛型类型参数T,可以大大 ...
- C#数据类型及差异(复习专用)
一.数据类型 值类型 类型 描述 范围 默认值 bool 布尔值 True 或 False False byte 8 位无符号整数 0 到 255 0 char 16 位 Unicode 字符 U + ...
- Alyona and towers CodeForces - 739C (线段树)
大意: 给定序列, 要求实现区间加, 询问整个序列最长的先增后减的区间. 线段树维护左右两端递增,递减,先增后减的长度即可, 要注意严格递增, 合并时要注意相等的情况, 要注意相加会爆int. #in ...
- c语言参考书籍
很惭愧没能把c++学的很好,毕竟离开始工作只有2年时间,对自己要求不要过高,慢慢来吧.话说知道自己的不足,以后要更加抓紧了!fighting~ 现在计划着把c语言给学习一下了,当然这次指的是深入地学习 ...
- Leveling Ground(数论,三分法,堆)
Leveling Ground(数论,三分法,堆) 给定n个数和a,b每次可以选择一段区间+a,-a,+b或-b,问最少操作几次能把他们都变成0.n<=1e5. 首先差分一下序列,问题就会变成了 ...
- 【火车出栈】ZOJ - 2603 Railroad Sort
好久没写递归了,怕手生再来练练手. 题意:车轨上有上图所示的n个中转栈,现有2n个列车,给出列车初始编号序列.列车从最右边驶入车轨,并且列车只能从右向左移动,要求给出列车中转操作序列,使列车经过这n个 ...
- loj #2044. 「CQOI2016」手机号码
#2044. 「CQOI2016」手机号码 内存限制:256 MiB时间限制:1000 ms标准输入输出 题目类型:传统评测方式:文本比较 上传者: 匿名 提交提交记录统计讨论测试数据 题目描述 ...
- Canvas 与 Image 相互转换
转换 Image为 Canvas 要把图片转换为Canvas(画板,画布),可以使用canvas元素 context 的drawImage方法: 代码如下: // 把image 转换为 canvas对 ...
- [BOI2007]Sequence 序列问题 BZOJ1345
题目描述 对于一个给定的序列a1, …, an,我们对它进行一个操作reduce(i),该操作将数列中的元素ai和ai+1用一个元素max(ai,ai+1)替代,这样得到一个比原来序列短的新序列.这一 ...
- kuangbin专题十二 HDU1074 Doing Homework (状压dp)
Doing Homework Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...