题目概述: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
题目大意:有N个考场,每个考场里有K个学生,依次输入这些学生的考号与成绩,并按照成绩由高到低(如果成绩相同则按字典序由低到高)排序,并依次输出该学生成绩的总排名,考场号,以及在考场的排名。
题解:使用结构体储存学生信息,我的结构体共有5个变量,当然也有用4个的

struct student
{
char number[105];
int countnumber;
int lanknumber;
int all;
int score;
};

大致思路为使用两次sort排序,先在本考场内进行一次排序,得出学生在考场的位序,其次在全部学生进行一次排序。cmp构造如下:

bool cmp(student a, student b)
{
if (a.score != b.score)
return a.score > b.score;
if (a.score == b.score)
return strcmp(a.number, b.number) < 0;
}

注意在PTA上提交时要加上cstring头文件,否则会编译错误
AC代码

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include <cstring>
using namespace std;
struct student
{
char number[105];
int countnumber;
int lanknumber;
int all;
int score;
};
bool cmp(student a, student b)
{
if (a.score != b.score)
return a.score > b.score;
if (a.score == b.score)
return strcmp(a.number, b.number) < 0;
}
int main()
{
struct student box[30005];
int count, m = 0, n = 0, now1 = 1, now2 = 1;
int everycount[105];
cin >> count;
for (int t = 0; t < count; t++)
{
cin >> everycount[m];
for (int t1 = 0; t1 < everycount[m]; t1++)
{
cin >> box[n].number >> box[n].score;
box[n].countnumber = m+1;
n++;
}
sort(box + n - everycount[m], box + n, cmp);
now1 = 1, now2 = 1;
for (int t3 = n - everycount[m]; t3 < n; t3++)
{
if (t3 != 0 && box[t3 - 1].score == box[t3].score)
box[t3].lanknumber = box[t3 - 1].lanknumber;
else
box[t3].lanknumber = now2;
now2++;
}
m++; }
sort(box, box + n, cmp);
now1 = 1, now2 = 1;
for (int t3 = 0; t3 < n; t3++)
{
if (t3 != 0 && box[t3 - 1].score == box[t3].score)
box[t3].all = box[t3 - 1].all;
else
box[t3].all = now2;
now2++;
}
cout << n << endl;
for (int t5 = 0; t5 < n; t5++)
cout << box[t5].number << " " << box[t5].all << " " << box[t5].countnumber << " " << box[t5].lanknumber << endl; }

PAT甲级真题 A1025 PAT Ranking的更多相关文章

  1. PAT 甲级真题题解(1-62)

    准备每天刷两题PAT真题.(一句话题解) 1001 A+B Format  模拟输出,注意格式 #include <cstdio> #include <cstring> #in ...

  2. 1080 Graduate Admission——PAT甲级真题

    1080 Graduate Admission--PAT甲级练习题 It is said that in 2013, there were about 100 graduate schools rea ...

  3. PAT 甲级真题题解(63-120)

    2019/4/3 1063 Set Similarity n个序列分别先放进集合里去重.在询问的时候,遍历A集合中每个数,判断下该数在B集合中是否存在,统计存在个数(分子),分母就是两个集合大小减去分 ...

  4. PAT 甲级真题

    1019. General Palindromic Number 题意:求数N在b进制下其序列是否为回文串,并输出其在b进制下的表示. 思路:模拟N在2进制下的表示求法,“除b倒取余”,之后判断是否回 ...

  5. PAT甲级真题及训练集

    正好这个"水水"的C4来了 先把甲级刷完吧.(开玩笑-2017.3.26) 这是一套"伪题解". wacao 刚才登出账号测试一下代码链接,原来是看不到..有空 ...

  6. Count PAT's (25) PAT甲级真题

    题目分析: 由于本题字符串长度有10^5所以直接暴力是不可取的,猜测最后的算法应该是先预处理一下再走一层循环就能得到答案,所以本题的关键就在于这个预处理的过程,由于本题字符串匹配的内容的固定的PAT, ...

  7. 1018 Public Bike Management (30分) PAT甲级真题 dijkstra + dfs

    前言: 本题是我在浏览了柳神的代码后,记下的一次半转载式笔记,不经感叹柳神的强大orz,这里给出柳神的题解地址:https://blog.csdn.net/liuchuo/article/detail ...

  8. 1022 Digital Library——PAT甲级真题

    1022 Digital Library A Digital Library contains millions of books, stored according to their titles, ...

  9. PAT甲级真题打卡:1001.A+B Format

    题目: Calculate a + b and output the sum in standard format -- that is, the digits must be separated i ...

随机推荐

  1. python入门神书!|python编程从入门到实践|内附网盘链接带提取码|

    点击此处进入网盘下载地址 提取码:o39n 全书共有20章,书中的简介如下: 本书旨在让你尽快学会 Python ,以便能够编写能正确运行的程序 —— 游戏.数据可视化和 Web 应用程序,同时掌握让 ...

  2. html中input提示文字样式修改

    在很多网站上我们都看到input输入框显示提示文字,让我们一起来看看如果在input输入框中显示提示文字.我们只需要在<input>标签里添加:placeholder="提示文字 ...

  3. PHP min() 函数

    实例 通过 min() 函数查找最小值: <?php高佣联盟 www.cgewang.comecho(min(2,4,6,8,10) . "<br>");echo ...

  4. PDOStatement::closeCursor

    PDOStatement::closeCursor — 关闭游标,使语句能再次被执行.(PHP 5 >= 5.1.0, PECL pdo >= 0.9.0) 说明 语法 bool PDOS ...

  5. 畅购商城(四):Lua、OpenResty、Canal实现广告缓存与同步

    好好学习,天天向上 本文已收录至我的Github仓库DayDayUP:github.com/RobodLee/DayDayUP,欢迎Star,更多文章请前往:目录导航 畅购商城(一):环境搭建 畅购商 ...

  6. 【CSP2019】括号树 题解(递推+链表)

    前言:抽时间做了做这道题,把学长送退役的题. ----------------- 题目链接 题目大意:定义$()$是合法括号串.如果$A,B$是合法括号串,那么$(AB),AB$为合法括号串.现给定根 ...

  7. Linux学习笔记之如何设置vim中的格式如行号等

    在我们编写代码程序时,我们时常想追求更好的格式,下面写一下我认为挺实用的格式命令以及如何更改 如果我们打开vim在其命令模式中输入格式命令时,下一次重新打开vim还是会和原先一样,所以我们需更改其配置 ...

  8. java_static、final、super、this关键字的使用

    static关键字 它可以修饰的成员变量和成员方法,被修饰的成员是属于类的,而不是单单是属于某个对象. 当 static 修饰成员变量时,该变量称为类变量 static 数据类型 变量名: 当 sta ...

  9. (数据科学学习手札92)利用query()与eval()优化pandas代码

    本文示例代码已上传至我的Github仓库https://github.com/CNFeffery/DataScienceStudyNotes 1 简介 利用pandas进行数据分析的过程,不仅仅是计算 ...

  10. C#LeetCode刷题-设计

    设计篇 # 题名 刷题 通过率 难度 146 LRU缓存机制   33.1% 困难 155 最小栈 C#LeetCode刷题之#155-最小栈(Min Stack) 44.9% 简单 173 二叉搜索 ...