PAT A1025 PAT Ranking(25)
题目描述
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.
输入格式
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.
输出格式
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.
输入样例
2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85
输出样例
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
全部AC
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
//p115
using namespace std;
const int maxn = 30010;
struct Student {
char registration_number[20]; //考生id
int score; //考生成绩
int final_rank; //最终排名
int location_number; //考室号
int local_rank; //考室排名
}stu[maxn];
bool cmp(Student A, Student B) {
if(A.score != B.score) return A.score > B.score; //AB成绩不同,按成绩从大到小排序
else if(A.score == B.score) return strcmp(A.registration_number, B.registration_number) < 0; //AB成绩相同,则按照准考证从小到大排序
}
int main(){
#ifdef ONLINE_JUDGE
#else
freopen("1.txt", "r", stdin);
#endif // ONLINE_JUDGE}
int N; //考室数量
scanf("%d", &N);
int a = 0; //初始化考生存储位置
for(int i = 0; i < N; i++) {
int K; //考室中考生的数量
scanf("%d", &K);
//输入各个考室考生的注册号和成绩
for(int j = 0; j < K; j++) {
stu[a].location_number = i + 1;
scanf("%s %d", stu[a].registration_number, &stu[a].score);
a++;
}
}
//初始化每个教室排名
int lrank[N+1] = {0};
int lrealrank[N+1] = {0};
//memset(lrank, 1, N+1);
//按考生成绩从大到小排序
sort(stu, stu+a, cmp);
int rank = 1; //总排名
for(int i = 0; i < a; i++) {
//printf("registration_number:%s location_number:%d score:%d \n", stu[i].registration_number, stu[i].location_number, stu[i].score);
//总排名
if(i == 0) stu[i].final_rank = rank;
else if(i != 0 && stu[i].score == stu[i-1].score) stu[i].final_rank = stu[i-1].final_rank;
else if(stu[i].score < stu[i-1].score) stu[i].final_rank = ++rank;
rank = i+1; //更新总排名
//教室排名
if(i != 0 && stu[i].score == stu[i-1].score && stu[i].location_number == stu[i-1].location_number) { //在同个教室中分数相同
stu[i].local_rank = stu[i-1].local_rank;
lrealrank[stu[i].location_number]++;
} else {
stu[i].local_rank = lrank[stu[i].location_number]; //在同个教室中分数不相同
lrank[stu[i].location_number]++;
lrealrank[stu[i].location_number]++;
}
lrank[stu[i].location_number] = lrealrank[stu[i].location_number];
}
printf("%d\n", a);
for(int i = 0; i < a; i++) {
printf("%s %d %d %d\n", stu[i].registration_number, stu[i].final_rank, stu[i].location_number, stu[i].local_rank+1);
}
return 0;
}
PAT A1025 PAT Ranking(25)的更多相关文章
- PAT A1025 pat ranking
有n个考场,每个考场都有若干数量个考生,现给出各个考场中考生的准考证号和分数,要求将所有考生的分数从高到低排序,并输出 #include<iostream> #include<str ...
- A1025 PAT Ranking (25)(25 分)
A1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer ...
- pat1025. PAT Ranking (25)
1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...
- 1025 PAT Ranking (25分)
1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...
- PAT甲级:1025 PAT Ranking (25分)
PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...
- PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- [PAT] 1141 PAT Ranking of Institutions(25 分)
After each PAT, the PAT Center will announce the ranking of institutions based on their students' pe ...
- PAT 1085 PAT单位排行(25)(映射、集合训练)
1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤105),即考生人数.随 ...
- PTA PAT排名汇总(25 分)
PAT排名汇总(25 分) 计算机程序设计能力考试(Programming Ability Test,简称PAT)旨在通过统一组织的在线考试及自动评测方法客观地评判考生的算法设计与程序设计实现能力,科 ...
随机推荐
- Bert系列 源码解读 四 篇章
Bert系列(一)——demo运行 Bert系列(二)——模型主体源码解读 Bert系列(三)——源码解读之Pre-trainBert系列(四)——源码解读之Fine-tune 转载自: https: ...
- 【模板】强连通分量和tarjan算法
看了好久才终于明白了这个算法..复杂度是O(n+m). 我觉得这个算法不是很好理解,但是看懂了以后还是觉得听巧妙的. 下面给出模板代码和三组简单数据帮助理解. 代码如下: #include <s ...
- JAVA之工作线程数究竟要设置多少
一.需求缘起 Web-Server通常有个配置,最大工作线程数,后端服务一般也有个配置,工作线程池的线程数量,这个线程数的配置不同的业务架构师有不同的经验值,有些业务设置为CPU核数的2倍,有些业务设 ...
- 查看MySQL 连接信息--连接空闲时间及正在执行的SQL
MySQL 客户端与MySQL server建立连接后,就可以执行SQL语句了. 如何查看一个连接上是否正在执行SQL语句,或者连接是否处于空闲呢? 下面我们做下测试. 1.查看连接的空闲时间 首先看 ...
- <HTML>在一个表格内嵌套另一个表格时,如何居中?
在一个表格内嵌套另一个表格时,如何居中? 假设大表格为: <table id="tableRow"> <tr> <th>City</th& ...
- nginx开启目录浏览,解决中文乱码问题
nginx开启目录浏览,解决中文乱码问题 方法如下: server { listen 80; #listen [::]:80; server_name gongzi.liwenhui.xin gz.l ...
- Oracle存储过程、游标、函数
SQL99是什么 (1)是操作所有关系型数据库的规则 (2)是第四代语言 (3)是一种结构化查询语言 (4)只需发出合法合理的命令,就有对应的结果显示 SQL的特点 (1)交互性强,非过程化 (2)数 ...
- 表单中使用<button>的注意点
本文主要记录了我调查问题的思路想法,想看结论的同学直接拖到最后吧 上周在做项目的时候,有一个需求是在页面中加一个按钮,点一下查询数据库将内容填充在表格中.这不是很简单嘛,页面加个按钮,发送ajax请求 ...
- Spring策略模式的实现
场景: 有时候一个业务方法有多个实现类,需要根据特定的情形进行业务处理. 例如:商店支付,我们可以使用支付宝.微信扫描农行.xxx行的快捷支付(而不是微信支付.支付宝支付二维码)购买商品. 实现代码( ...
- 手写web框架之实现依赖注入功能
我们在Controller中定义了Service成员变量,然后在Controller的Action方法中调用Service成员变量的方法,那么如果实现Service的成员变量? 之前定义了@Injec ...