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. Bash cat EOF

    cat <<EOF > ciphers.txt> ECDHE-ECDSA-AES128-GCM-SHA256> ECDHE-RSA-AES128-GCM-SHA256&g ...

  2. k8s删除pod一直处于terminating状态

    我这里的pod是与nfs有关,nfs挂载有问题导致pod有问题,执行完删除命令以后看到pod一直处于terminating的状态. 这种情况下可以使用强制删除命令: kubectl delete po ...

  3. 记一次网络故障——pod间无法通信

    一.背景 集群是二进制部署 部署完成后一起正常,各种资源对象均可正常创建. 部署应用后发现无法跨节点通信,且pod的ip都是172.17.0.0段的 二.排查过程层 查看节点路由,发现docker0网 ...

  4. SQLServer -------- 解决忘记sa 密码,创建一个新的

    时间真的是一个可怕的武器,你可以不服老,但是你不能改变,你年纪的增长,在我们创建数据库的时候,会创建sa 和密码,但是密码忘记怎么办, 提供一种方法,创建一个新的进行软件部署 实现方法:1.找到安全性 ...

  5. 如何解决Requests的SSLError(转)

    add by zhj: 我使用方法2“更新系统的certificate”解决了问题 原文:https://www.jianshu.com/p/8deb13738d2c 这两天在Linux上爬Googl ...

  6. 『正睿OI 2019SC Day1』

    概率与期望 总结 老师上午几乎是在讲数学课,没有讲什么和\(OI\)有关的题目,所以我就做了一点笔记. 到了下午,老师讲完了有关知识点和经典模型,就开始讲例题了.前两道例题是以前就做过的,所以没有什么 ...

  7. 运行带有Activiti modeler时,出现这样的报错: java.rmi.AccessException: Cannot modify this registry

    最近在做整合Activiti Modeler工作流在线设计器的工作,运行IDEA时,出现了这样一个错误信息: 原因及解决办法:   Activiti默认打开了jmx功能,默认端口为1099,idea中 ...

  8. H5+asp.net 微信开发 遇到过的坑

    一.微信授权登录 1. 根据code 获取_access_tokens 2. 根据取到的openid和_access_tokens获取用户信息最神奇的是我用我自己的微信账号测试,一开始还可以取到tok ...

  9. spring mvc 服务器端输出一条可执行js

    @RequestMapping(value = "/test",produces = "text/html; charset=UTF-8") @Response ...

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

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