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. JQuery_自带的动画效果

    1.方法: show:显示选中元素. hide:隐藏选中元素. toggle:显示或隐藏选中元素. fadeIn:将选中元素的不透明度逐步提升到100%. fadeOut:将选中元素的不透明度逐步降为 ...

  2. devstack 安装(centos7)

    1. 创建devstack用户 sudo useradd -s /bin/bash -d /opt/stack -m stackecho "stack ALL=(ALL) NOPASSWD: ...

  3. python-lambda用法

    前言: lambda函数也叫匿名函数,即,函数没有具体的名称. 一.基础 lambda语句构建的其实是一个函数对象.匿名函数有个限制,就是只能有一个表达式,不用写return,返回值就是该表达式的结果 ...

  4. [2019BUAA软件工程]结对编程感想

    结对编程感想 写在前面   本博客为笔者在完成软件工程结对编程任务后对于编程过程.最终得分的一些感想与经验分享.此外笔者还对于本课程的结对编程部分提出了一些建议. Tips Link 作业要求博客 2 ...

  5. 【MOOC EXP】Linux内核分析实验六报告

    程涵  原创博客 <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 进程的描述和进程的创建 知识点梳理: ...

  6. [转帖]Intel新一代Xeon完整曝光

    AMD已经官宣7nm工艺的第二代EPYC霄龙服务器平台,今年上半年就会大规模出货,而在Intel这边,由于10nm工艺进展还是不够快,在服务器上还是需要14nm继续打天下,而且还有两代14nm工艺产品 ...

  7. 转载 linux常用的监控命令工具

    工具 简单介绍top 查看进程活动状态以及一些系统状况vmstat 查看系统状态.硬件和系统信息等iostat 查看CPU 负载,硬盘状况sar 综合工具,查看系统状况mpstat 查看多处理器状况n ...

  8. using 的三种使用方式

    using 关键字有两个主要用途: 作为指令:用于为命名空间创建别名或导入在其他命名空间中定义的类型. 作为语句:用于定义一个范围,在此范围的末尾将释放对象. 此外,使用 using 静态指令可定义一 ...

  9. 一步步分析为什么B+树适合作为索引的结构

    在MySQL中,主要有四种类型的索引,分别为:B-Tree索引,Hash索引,Fulltext索引和R-Tree索引,本文讲的是B-Tree索引. 什么是索引 索引(Index)是帮助数据库高效获取数 ...

  10. 对delphi中的数据敏感控件的一点探索

    一直对delphi数据敏感控件很好奇,感觉很神奇.只要简单设置一下,就显示和编辑数据,不用写一行代码. 如果不用数据敏感控件,编辑一个表字段数据并保存,我相信应用如下代码. Table1.edit, ...