PAT甲级——A1025 PAT Ranking
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
简单的排序题,使用结构体
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
struct Node
{
string No;
int score, final_rank, location_num, local_rank;
}; bool cmp(Node* a, Node* b)
{
return (a->score == b->score) ? (a->No < b->No) : (a->score > b->score);
}
int N, K;
vector<Node*>allPerson;
int main()
{
cin >> N;
for (int i = ; i <= N; ++i)
{
cin >> K;
vector<Node*>temp;
for (int j = ; j < K; ++j)
{
Node* node = new Node;
cin >> node->No >> node->score;
node->location_num = i;
temp.push_back(node);
}
sort(temp.begin(), temp.end(), cmp);
for (int j = ; j < temp.size(); ++j)
{
if (j > && temp[j]->score == temp[j - ]->score)
temp[j]->local_rank = temp[j - ]->local_rank;
else
temp[j]->local_rank = j + ;
}
allPerson.insert(allPerson.end(), temp.begin(), temp.end());
}
sort(allPerson.begin(), allPerson.end(), cmp);
cout << allPerson.size() << endl;
for (int j = ; j < allPerson.size(); ++j)
{
if (j> && allPerson[j]->score == allPerson[j - ]->score)
allPerson[j]->final_rank = allPerson[j - ]->final_rank;
else
allPerson[j]->final_rank = j + ;
cout << allPerson[j]->No << " " << allPerson[j]->final_rank << " " <<
allPerson[j]->location_num << " " << allPerson[j]->local_rank << endl;
}
return ;
}
PAT甲级——A1025 PAT Ranking的更多相关文章
- PAT 甲级 1141 PAT Ranking of Institutions
https://pintia.cn/problem-sets/994805342720868352/problems/994805344222429184 After each PAT, the PA ...
- 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 C++/Java
Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Z ...
- PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)
题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...
- 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 ...
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
随机推荐
- redis:info详解
[root@192.168.56.159 redis6380]redis-cli -a xxx info# Serverredis_version:3.0.7 redis_version: Redi ...
- [kuangbin带你飞]专题一 简单搜索 - B - Dungeon Master
#include<iostream> #include<cstdio> #include<string> #include<vector> #inclu ...
- python常用包及功能介绍
1.NumPy数值计算 NumPy是使用Python进行科学计算的基础包,Numpy可以提供数组支持以及相应的高效处理函数,是Python数据分析的基础,也是SciPy.Pandas等数据处理和科学计 ...
- GNU GRUB引导的默认启动项是ubuntu
安装了ubuntu16.04后,GNU GRUB引导的默认启动项是ubuntu,如果希望默认启动项是windows,修改方法如下: step1. 进入Ubuntu系统,打开终端,输入 sudo ged ...
- Longge's problem
Longge's problem 求\(\sum_{i=1}^ngcd(i,n)\),\(n< 2^{31}\). 解 理解1: 注意式子的实际意义,显然答案只可能在n的约数中,而现在问题变成了 ...
- 便携版Mysql安装
目录 1.安装 0.Mysql下载地址 1.解压 2.在主目录下新建data和tempData两个文件夹 3.配置环境变量 4.配置my.ini 5.安装服务(管理员模式CMD) 6.清空data文件 ...
- Python3基础笔记_字符串类型
# 1.Python转义字符 a = "sqwerdf" # 2.Python字符串运算符 ''' + 字符串连接 a + b 输出结果: HelloPython * 重复输出字符 ...
- 利用eclipse通过mybatis进行查询汉字字符时候无法显示结果,但是直接通过cmd窗口可以显示的解决方法
将数据库配置文件中的url写成如下的形式就可以成功查询: url = "jdbc:mysql://127.0.0.1:3306/test?characterEncoding=utf8&quo ...
- DuiLib学习笔记2.写一个简单的程序
我们要独立出来自己创建一个项目,在我们自己的项目上加皮肤这才是初衷.我的新建项目名为:duilibTest 在duilib根目录下面有个 Duilib入门文档.doc 我们就按这个教程开始入门 首先新 ...
- 聊聊MVC和模块化以及MVVM和组件化
原文链接 小寒的博客,带你理解更深的世界 面向对象,模块化和MVC 面向对象是指把写程序映射到现实生活,从而一来逻辑性更强,更容易写好代码,二来代码很贴切,通俗易懂,更被人理解,三来更加容易拓展和管理 ...