PAT 甲级 1025.PAT Ranking C++/Java
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的更多相关文章
- PAT 甲级 1025 PAT Ranking
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- PAT甲级——1025 PAT Ranking
1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...
- PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)
题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...
- 【PAT】1025. PAT Ranking (25)
题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...
- PAT 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- PAT甲级——A1025 PAT Ranking
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhe ...
- PAT甲级1075 PAT Judge
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805393241260032 题意: 有m次OJ提交记录,总共有k道 ...
- PAT 甲级 1075 PAT Judge (25分)(较简单,注意细节)
1075 PAT Judge (25分) The ranklist of PAT is generated from the status list, which shows the scores ...
- PAT甲级——A1075 PAT Judge
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
随机推荐
- 计算GPS点之间的距离
latitude纬度 longtitude经度 // 求弧度 double getRadian(double d) { return d * PI / 180.0; //角度1? = π / 180 ...
- windows 中如何定位恶意软件的藏身位置
目录 一: 下载spy++ 打开后 点击 搜索下面的查找窗口(Alt+F3) 点击 查找程序工具 右侧的 靶子一样的图标,鼠标左键按住不放,拖放到 弹窗上面,弹窗周围会出现 黑框. 然后 我们点击确定 ...
- 每月IT摘录201911
技术 1.以 MySQL 的 InnoDB 引擎为例,由于 MySQL 中有两套日志机制,一套是存储层的 redo log,另一套是 server 层的 binlog,每次更新数据都要对两个日志进行更 ...
- JConsole远程配置
JConsole是JDK自带的内存监控工具 1.linux配置tomcat-9.x 修改setenv.sh文件(默认没有的,需自己创建),增加配置: #!/bin/sh JAVA_HOME=/usr/ ...
- Jenkins+Docker+Git+Registry
从0到1体验Jenkins+Docker+Git+Registry实现CI自动化发布 笔者:@拿着保温瓶的年轻人 目录: 一.前言 二.发布流程 三.环境准备 四.部署思路梳理 五.三台机器上操作 ...
- ps 简单使用 ----- 将图片静态图片制作成动图
1. 准备好你需要静态图片 放到文件夹中 2.打开ps 软件 将右上角切换为 动感 3.观察下方时间轴 点击加号 将图片导入 按住shift 选择图片 4.切换为帧格式 选择循环 ...
- 贪心 --- Y2K Accounting Bug
Y2K Accounting Bug Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9691 Accepted: 483 ...
- 桥接(Bridge)模式
桥接模式又称为柄体模式或接口模式.桥接模式的用意就是"将抽象化与实现化解耦,使得二者可以独立变化". 抽象化: 存在于多个实体中的共同的概念性联系,就是抽象化.作为一个过程,抽象化 ...
- idea(2018.3.5)破解
第一步:下载idea,https://www.jetbrains.com/idea/download/#section=windows,双击进行安装 第二步:下载破解的jar包:链接:https:// ...
- Golang 调用 C/C++,例子式教程
大部分人学习或者使用某样东西,喜欢在直观上看到动手后的结果,才会有继续下去的兴趣. 前言: Golang 调用 C/C++ 的教程网上很多,就我目前所看到的,个人见解就是比较乱,坑也很多.希望本文能在 ...