1025. PAT Ranking (25)

时间限制
200 ms
内存限制
65536 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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)的更多相关文章

  1. A1025 PAT Ranking (25)(25 分)

    A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...

  2. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

  3. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  4. 【PAT】1025. PAT Ranking (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...

  5. 1025. PAT Ranking (25)

    题目如下: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology ...

  6. 1025 PAT Ranking (25)(25 point(s))

    problem Programming Ability Test (PAT) is organized by the College of Computer Science and Technolog ...

  7. PAT A1025 PAT Ranking(25)

    题目描述 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology o ...

  8. 1025 PAT Ranking (25 分)

    Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...

  9. 1025 PAT Ranking (25分) 思路分析 +满分代码

    题目 Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of ...

随机推荐

  1. EIP-uni-app框架-建立项目

    uni-app介绍 uni-app 是一个使用 Vue.js 开发跨平台应用的前端框架,开发者编写一套代码,可编译到iOS.Android.H5.小程序等多个平台.uni-app在跨端数量,扩展能力, ...

  2. 搭建 pytorch框架

    Pytorch 发布了1.0,对windows的支持效果更好,因此,今天试了一下安装Pytorch.安装速度确实很快,安装也很方便. 进入pytorch的官网,选择对应的版本 根据版本输入相应命令 注 ...

  3. utf-8-BOM删除bom

    utf-8  bom,去除bom //开始 function file_bom($wenjian,$remove = true) { //读取文件,将文件写入字符串    $contents = fi ...

  4. b,u,i,s,这些被删除的标签以及用来替换他们的标签

    加粗文字 给文字加下划线 倾斜文字 给文字加删除线 这些是以前的HTML语言修饰文字用的,没有语义,所以被删除,不到万不得已 不能使用,HTML给了新的标签替换他们,并且有语义 定义重要性强调的文字 ...

  5. FPGA实战操作(1) -- SDRAM(Verilog实现)

    对SDRAM基本概念的介绍以及芯片手册说明,请参考上一篇文章SDRAM操作说明. 1. 说明 如图所示为状态机的简化图示,过程大概可以描述为:SDRAM(IS42S16320D)上电初始化完成后,进入 ...

  6. 前端优化系列之一:dns预获取 dns-prefetch 提升页面载入速度

    问题:怎么做到dns域解析?   用于优化网站页面的图片   问题:怎么提升网站性能? dns域解析,是提升网站的一个办法.   DNS Prefetch,即DNS预获取,是前端优化的一部分. 一般来 ...

  7. 老男孩python作业8-学员管理系统

    学员管理系统开发: 需求: 用户角色,讲师\学员, 用户登陆后根据角色不同,能做的事情不同,分别如下 讲师视图 管理班级,可创建班级,根据学员qq号把学员加入班级 可创建指定班级的上课纪录,注意一节上 ...

  8. 网络中常用的各种协议(针对TCP/IP协议组)

    网络层: ip协议->网络互连协议 用途:将多个包在网络中联系起来,传输数据包(不可靠传输),最基本功能就是寻址和分段功能,不提供端到端,路由到路由的确认,不提供重发和流量控制.是计算机网络能狗 ...

  9. git学习中遇到的疑难杂症

    GIT仓库如何恢复到前一次提交 一.通过使用Git版本恢复命令reset,可以回退版本 reset命令有3种方式: 1.git   reset   –mixed:此为默认方式,不带任何参数的git r ...

  10. C#工具类之Xml序列化扩展类

    using System; using System.IO; using System.Linq; using System.Runtime.Serialization; using System.T ...