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. Scrum与看板区别

    看板:在制品(work-in-progress, WIP)必须被限制 WIP上限和拉动式生产   1. Scrum与看板简述 Scrum:组织拆分,工作拆分,开发时间拆分,优化发布计划,过程优化 看板 ...

  2. ACM-ICPC 2017 Asia Urumqi:A. Coins(DP)

    挺不错的概率DP,看似基础,实则很考验扎实的功底 这题很明显是个DP,为什么???找规律或者算组合数这种概率,N不可能给的这么友善... 因为DP一般都要在支持N^2操作嘛. 稍微理解一下,这DP[i ...

  3. 12.18 Daily Scrum

    最近大家确实都很忙,所以所有功能的实现要等到下周.   Today's Task Tomorrow's Task 丁辛 实现和菜谱相关的餐厅列表. 实现和菜谱相关的餐厅列表.             ...

  4. 【Beta阶段】M2事后分析

    先上照片,最后一次开会了啊... 计划 你原计划的工作是否最后都做完了? 如果有没做完的,为什么? 答:没有全部做完,到目前为止,我们的还有几个实验的报告生成功能没有上线.这几个实验的数据处理文件已经 ...

  5. Linux内核分析作业第六周

    创建新进程的过程 一.进程的描述 为了管理进程,内核必须对每个进程进行清晰的描述,进程描述符提供了内核所需了解的进程信息. 1.进程控制块PCB——task_struct 操作系统的三大管理功能 进程 ...

  6. 20135337——Linux实践三:ELF文件格式(64位系统,简单分析)

    ELF文件格式简单分析 (具体分析见上一篇ELF文件格式32位系统) ELF-header 第一行: 457f 464c :魔数: 0201 :64位系统,小端法 01 :文件头版本 剩余默认0: 第 ...

  7. NumsCount (java)

    package com.home.test;       import java.util.Arrays;       public class NumsCount {       public vo ...

  8. Linux CentOS虚拟机网卡配置

    最近在VMware安装CentOS6.5之后,每次从宿主机访问虚拟机的Oracle时,都要修改IP地址,因为没有设置虚拟机的IP,所以每次开机之后虚拟机的IP地址都是随机的,于是研究了下给虚拟机配置静 ...

  9. [转帖] SQL参数化的优点 CopyFrom https://www.cnblogs.com/-lzb/articles/4840671.html

    梦在远方的小猪 感谢原作者...  后面总结的五点感觉挺好的.. 自己之前的知识点一直没有串起来. 转帖记录一下感谢. sql参数化参数化 说来惭愧,工作差不多4年了,直到前些日子被DBA找上门让我优 ...

  10. Node 表单query

    //#使用nodejs编写动态的web服务器//1:加载需要模块 fs http urlconst fs = require("fs");const http = require( ...