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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct{
char regist[];
int final_rank;
int location;
int local_rank;
int grade;
}info;
bool cmp(info a, info b){
if(a.grade != b.grade)
return a.grade > b.grade;
else
return strcmp(a.regist, b.regist) < ;
}
int main(){
int N, K, head = , rear = ;
info students[];
scanf("%d", &N);
for(int i = ; i < N; i++){
scanf("%d", &K);
head = rear;
for(int j = ; j < K; j++){
scanf("%s%d",students[rear].regist, &(students[rear].grade));
students[rear].location = i + ;
rear++;
}
sort(students + head, students + rear, cmp);
students[head].local_rank = ;
for(int j = ; j < K; j++){
if(students[head + j].grade == students[head + j - ].grade)
students[head + j].local_rank = students[head + j - ].local_rank;
else
students[head + j].local_rank = j + ;
}
}
sort(students, students + rear, cmp);
students[].final_rank = ;
printf("%d\n", rear);
printf("%s %d %d %d\n", students[].regist, students[].final_rank, students[].location, students[].local_rank);
for(int i = ; i < rear; i++){
if(students[i].grade == students[i - ].grade)
students[i].final_rank = students[i - ].final_rank;
else
students[i].final_rank = i + ;
printf("%s %d %d %d\n", students[i].regist, students[i].final_rank, students[i].location, students[i].local_rank);
}
cin >> N;
return ;
}

总结:

1、题目要求:按照最终排名的非降序排列,如果最终排名相同,则按照id的非降序排列。由样例可知,分数相同的人排名相同,但相同排名的人均会占一个位置(如有3个人并列第一, 则第四个人排名为第四而非第二)。

2、依旧使用struct记录学生成绩和信息。使用sort函数来排序。sort(首元素地址,尾元素的下一个地址,cmp函数),如排序a[0]~a[5],应填sort(a, a + 6, cmp)。在cmp函数中, 如果需要降序排序,则 return a > b,反之亦然。

3、字符串比较大小,可以使用strcmp(a, b),若a < b,返回负数,a = b返回0,a > b,返回正数。需要include <string.h>。

A1025. PAT Ranking的更多相关文章

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

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

  2. PAT A1025 PAT Ranking(25)

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

  3. PAT甲级——A1025 PAT Ranking

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

  4. PAT甲级真题 A1025 PAT Ranking

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

  5. PAT A1025 pat ranking

    有n个考场,每个考场都有若干数量个考生,现给出各个考场中考生的准考证号和分数,要求将所有考生的分数从高到低排序,并输出 #include<iostream> #include<str ...

  6. PAT_A1025#PAT Ranking

    Source: PAT A1025 PAT Ranking Description: Programming Ability Test (PAT) is organized by the Colleg ...

  7. PAT Ranking (排名)

    PAT Ranking (排名) Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  8. 1025 PAT Ranking[排序][一般]

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

  9. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

随机推荐

  1. WPF开发汽车采样机上位机软件

    由于项目需要,需开发同一套汽车.火车.皮带采样机的上位机软件. 看过之前的上位机软件,老版本都是DelPhi.VB开发,稍微新语言开发的是采用winform开发.要不就是使用组态软件. Delphi语 ...

  2. left join 右表数据不唯一的情况解决方法

    https://blog.csdn.net/u010089432/article/details/52165026

  3. M2postmortem

    设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 答:我们的软件主要解决信息提取的问题.定义清晰:要提取的内容包括于计算机科学相关内容的标题.作者. ...

  4. Python小笔记

    最近在学习Python  以前也学过一些编程语言 但是都不扎实  由于工作的原因 需要学习Python做一些处理 刚开始学习总有多多少少的不适应  从今天开始打算将我在学习中遇到的困难以及疑问记录下来 ...

  5. 第二次作业:Git的安装与使用

    ---恢复内容开始--- 本次作业要求来自:https://edu.cnblogs.com/campus/gzcc/GZCC-16SE1/homework/2103 1.首先安装git bash软件, ...

  6. JavaScript解决一个带验证的Form两个Submit事件(一个页面保持不动【AJAX实现】,一个页面提交并跳转)的场景

    <form class="form-horizontal" action="/biz/patent/edit" method="post&quo ...

  7. Oracle备份恢复简单过程以及中间的坑.

    Oracle 冷备: 貌似需要dbca创建一致的oracle instance 服务器配置版本尽量相同,安装路径相同. 关闭Oracle服务 将oracle app 目录下的oradata以及有快速闪 ...

  8. [转帖]CR3,PDE,PTE,TLB 内存管理的简单说明

    CR3,PDE,PTE,TLB  Copy From https://www.cnblogs.com/zzSoftware/archive/2013/02/11/2908824.html   网上关于 ...

  9. [工作相关] GS产品使用LInux下Oracle数据库以及ASM存储时的数据文件路径写法.

    1. 自从公司的GS5版本就已经支持Linux下的oracle数据库通过安装工具自动安装注册了, 只不过路径需要使用linux的命名规则, 如图: /home/oracle/ 注意 最后是有一个 斜线 ...

  10. 关于linux上文件无法正确显示中文的情况解决

    其实有遇到过多次,而且还有几次是css在预编译的时候,系统编码不对也会报错. 贴一个写的还不错的文章:http://www.360doc.com/content/11/0728/09/7102324_ ...