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 ...
随机推荐
- HeadFirst设计模式中的笔记
1.『策略模式』 定义了算法族,分别封装起来,让它们之间可以互相替换,此模式让算法的变化独立于使用算法的客户. OO基础:抽象 封装 多态 继承 OO原则:封装变化 多用组合,小用继承 针对接口编 ...
- 验证视图状态MAC失败的解决办法
在网上搜寻了很久看了很多关于MAC验证视图状态失败的解决方法.大部分人都说是在页里或web.config里加 EnableEventValidation="false" Enabl ...
- Data Base System.Data.OracleClient requires Oracle client software version 8.1.7 or greater解决方案
System.Data.OracleClient requires Oracle client software version 8.1.7 or greater解决方案 一.问题: 1.通过Syst ...
- 利用excel制作二维码
1 将想要通过扫描二维码访问的目标网址放入A1单位格 2 在excel 编辑区右击选择“自定义功能区” 3 然后将“开发者工具”选上 4 点击菜单栏的“开发者工具---插入--->其他控件” 5 ...
- 温故而知新_C语言_递归
递归. 是的,差不多就是这种感觉.上面就是类似递归的显示表现. 2017 10 24更新: 递归这个问题放了很久.也没有写.大概是自己还没有好好理解吧. 在这里写下自己理解的全部. 一 何为递归. 字 ...
- 容器编排之Kubernetes1.10.2安装与配置
k8s 1.10.2 https搭建文档 1.下载k8s镜像 方式一:docker hub + github,需要创建一个docker hub账户,连接指定的github账户,docker hub会从 ...
- C:简单的学生信息处理程序实现
描述 在一个学生信息处理程序中,要求实现一个代表学生的类,并且所有成员变量都应该是私有的. (注:评测系统无法自动判断变量是否私有.我们会在结束之后统一对作业进行检查,请同学们严格按照题目要求完成,否 ...
- sql开发技巧总结-2
---恢复内容开始--- 1.如何进行行列转换 需求: 列转换成行 select a.`user_name`,sum(b.kills) from user1 a join user_kills b o ...
- luogu2658 GCD(莫比乌斯反演/欧拉函数)
link 给定整数N,求1<=x,y<=N且Gcd(x,y)为素数的数对(x,y)有多少对. 1<=N<=10^7 (1)莫比乌斯反演法 发现就是YY的GCD,左转YY的GCD ...
- PHP删除目录下包含某个字符串的全部文件
//获取全部的路径 function tree(&$arr_file, $directory, $dir_name='') { $mydir = dir($directory); whi ...