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 (≤), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤), 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个(<= 100)考场,每个考场有K(<= 300)名考生,给出每个考场的考生的考号,分数

输出所有考生的编号,总排名,考场号,考场内排名(按照非递减顺序输出)

分析:

如果考生的分数相同,就按照编号小到大输出(考号小的优先输出)

先按照考场内对考生进行排序,将结果保存到总考生数组,再对总考生进行排序

C++实现:

 #include <iostream>
#include <algorithm>
#include <string>
#include <vector>
using namespace std; typedef struct Student
{
string id; //考号
int score; //分数
int location; //地区
int local_rank; //地区排名
int total_rank; //总排名
}Student; bool myCmp(Student a, Student b)
{
if (a.score != b.score)
{
return a.score > b.score;
}
else
{
return a.id < b.id;
}
} int main()
{
int N; //考场数
cin >> N; int localNum = ; //考场人数
int totalNum = ; //总人数
vector<Student> totalStus; //保存所有考生的信息;
for (int i = ; i <= N; ++i)
{
cin >> localNum;
vector<Student> localStus(localNum);
for (int j = ; j < localNum; ++j)
{
cin >> localStus[j].id >> localStus[j].score;
localStus[j].location = i; //i个考场
}
sort(localStus.begin(), localStus.end(), myCmp);
localStus[].local_rank = ;
totalStus.push_back(localStus[]);
for (int j = ; j < localNum; ++j)
{
if (localStus[j].score == localStus[j - ].score)
{
//分数相同
localStus[j].local_rank = localStus[j - ].local_rank;
}
else
{
localStus[j].local_rank = j + ;
}
totalStus.push_back(localStus[j]);
}
totalNum += localNum;
} sort(totalStus.begin(), totalStus.end(), myCmp);
totalStus[].total_rank = ;
for (int i = ; i < totalNum; ++i)
{
if (totalStus[i].score == totalStus[i-].score)
{
totalStus[i].total_rank = totalStus[i - ].total_rank;
}
else
{
totalStus[i].total_rank = i + ; //注意这里的细节
}
}
cout << totalNum << endl;
for (int i = ; i < totalNum; ++i)
{
cout << totalStus[i].id << " " << totalStus[i].total_rank << " " << totalStus[i].location << " " << totalStus[i].local_rank << endl;
}
return ;
}

注意:如果分数与前一名分数相同,那么他们的排名相同。如果分数小于前一名的分数,那他的排名就是循环次数+1(因为如果前2人的排名都是1,那第i=2次循环时,第3个人的排名就是i + 1 = 3)

小结:

1. sort函数第三个参数cmp可以自己编写排序规则。

bool myCmp(Student a, Student b)
{
return a.score > b.score;
}

自定义排序规则:按照Student中的score来排序, return a.score > b.score; 按照分数从高到低排序

PAT 甲级 1025.PAT Ranking C++/Java的更多相关文章

  1. PAT 甲级 1025 PAT Ranking

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

  2. PAT甲级——1025 PAT Ranking

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

  3. PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)

    题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...

  4. 【PAT】1025. PAT Ranking (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...

  5. PAT 甲级 1141 PAT Ranking of Institutions

    https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...

  6. PAT甲级——A1025 PAT Ranking

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

  7. PAT甲级1075 PAT Judge

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032 题意: 有m次OJ提交记录,总共有k道 ...

  8. PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)

    1075 PAT Judge (25分)   The ranklist of PAT is generated from the status list, which shows the scores ...

  9. PAT甲级——A1075 PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

随机推荐

  1. Salesforce 开发整理(二)报表开发学习

    Salesforce提供了强大的报表功能,支持表格.摘要.矩阵以及结合共四种形式,本文探讨在站在开发的角度要如何理解报表. 一:查询报表基本信息报表在Sales force中是Report对象,基本的 ...

  2. 冰多多团队Gamma阶段项目展示

    [冰多多]Gamma项目展示 冰多多项目: 语音coding助手 Gamma阶段目标: 推出一个更加完整的IDE,完善编辑器功能,优化UI 一. 团队成员的简介和个人博客地址 成员 角色 个人博客地址 ...

  3. 【LeetCode】387. First Unique Character in a String

    Difficulty:easy  More:[目录]LeetCode Java实现 Description https://leetcode.com/problems/first-unique-cha ...

  4. java中什么是抽象类(abstract)

    一.什么是抽象类 由abstract修饰的方法叫抽象方法:由abstract修饰的类叫抽象类.抽象的类无法进行实例化,因为他不是具体存在的类,或者说这样的类还不够完善,不能直接使用new关键字调用其构 ...

  5. How to signout from an Azure Application?(转载)

    问: I have created a Azure AD application and a Web App. The Azure AD Application uses AAD Authentica ...

  6. Authentication using SASL/Kerberos

    Prerequisites KerberosIf your organization is already using a Kerberos server (for example, by using ...

  7. wps金山文档在线编辑--.Net 接入指南

    一.申请成为服务商,对金山文档在线服务进行申请 ①进入官网 https://open.wps.cn/ ②申请后如下图,点击右下角的进入服务 ③申请成功后 ④数据回调URL一定是服务器地址,本次我使用的 ...

  8. WinForm的TextBox限制只能输入数字并且屏蔽默认右键菜单

    基于Window消息实现 class TextBoxExt:TextBox { private const int WM_RBUTTONDOWN = 0x0204; private const int ...

  9. 聊聊Golang逃逸分析

    逃逸分析的概念,go怎么开启逃逸分析的log. 以下资料来自互联网,有错误之处,请一定告之. 什么是逃逸分析 wiki上的定义 在编译程序优化理论中,逃逸分析是一种确定指针动态范围的方法——分析在程序 ...

  10. windows下vmware和Hyper-v共存方法

    问题描述:环境:windows server 2012 r2系统下安装Hyper-v后,再安装Vmware 在Vmware中创建虚拟机,安装虚拟机系统的时候,vmware提示:VMware Works ...