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. item 11: 比起private undefined function优先使用deleted function

    本文翻译自modern effective C++,由于水平有限,故无法保证翻译完全正确,欢迎指出错误.谢谢! 博客已经迁移到这里啦 如果你为其他开发者提供代码,并且你想阻止他们调用一个特定的函数,你 ...

  2. zookeeper 动态管理nginx配置

    假设我们有一个场景,所有服务器共享同一份配置文件,我们肯定不可能单独手动维护每台服务器,这时可以利用zookeeper的配置管理功能. 环境:python + nginx + zookeeper 目的 ...

  3. Linux下FTP环境部署梳理(vsftpd和proftpd)

    在日常运维工作中,常部署到的FTP是vsftpd和proftd.之前写了Linux下FTP虚拟账号环境部署总结,下面简单说下本地用户下的FTP环境部署过程: 简单梳理下FTP主动和被动两种工作模式: ...

  4. linux下syslog-ng日志集中管理服务部署记录

    syslog是Linux系统默认的日志守护进程,默认的syslog配置文件是/etc/syslog.conf文件.syslog守护进程是可配置的,它允许人们为每一种类型的系统信息精确地指定一个存放地点 ...

  5. 后台跑包方法 断开ssh程序也能继续执行的方法screen命令

    aircrack-ng -w 字典路径 握手包路径 screen -S 001创建会话 screen -ls  列出窗口列表 screen -r 5位数字  进入会话指令 如果会话恢复不了,则是有可能 ...

  6. Week 7 迭代总结

    写在前面: 本次我为团队博客写了一篇总结,深刻总结了我们组发生的问题以及将来要做的事情.有兴趣请移步http://www.cnblogs.com/Buaa-software Week 7 Alpha轮 ...

  7. Liinux 学习心得

    Linux 内核学习心得 姬梦馨 原创作品 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 反汇编一个简 ...

  8. Linux内核分析 笔记八 进程的切换和系统的一般执行过程 ——by王玥

    一.进程切换的关键代码switch_to的分析 (一)进程调度与进程调度的时机分析 1.不同类型的进程有不同的调度需求 第一种分类: I/O-bound:频繁地进行I/O,花费很多的时间等待I/O操作 ...

  9. 同步手绘板——将View的内容映射成Bitmap转图片导出

    在Android中自有获取view中的cache内容,然后将内容转换成bitmap,方法名是:getDrawingCache(),返回结果为Bitmap,但是刚开始使用的时候,得到的结果都是null, ...

  10. 在win10开启HyperV(Pro以上版本)安装的Docker,如何远程管理其他机器(Linux或者Win)的docker容器

    用k8s能直接管理吗? 不把那个容器加入集群,可以吗?