[PAT A1025]PAT Ranking

题目描述

1025 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

分析

题目大意

就是输入考场数N,然后对于每个考场,输入考场内考生数目K,接下来K条输入是输入学生的准考证号和考试成绩,要求是成绩从高到低排序,对于相同的成绩按照准考证号从低到高排序

算法分析

  1. 其实题意很简单,就是考察简单的排序,我们考虑使用 sort ()函数来简化计算,当然,我们必须重写cmp函数!
  2. 然后对于空间的预分配,因为N<=100,K<=300,NK<=30000,所以数组大小为30010就行

具体代码如下:

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct student
{string r_number;//准考证号int l_number;  //考场号int l_rank = 0; //考场排名int grade;  //考试成绩
}; //结构体的设计
struct student stu[30010];  //数组的大小为30010,太小有可能通不过
bool cmp(student a, student b)
{if (a.grade != b.grade) return a.grade > b.grade;  //a,b学生成绩不相等,那么按降序排列else return a.r_number < b.r_number;  //a,b学生成绩相等,按准考证号升序排列
}
int main()
{int N, K, SUM = 0, R = 0;   //R用来计数cin >> N;for (int i = 0; i < N; i++){cin >> K;for (int j = 0; j < K; j++){student s;cin >> s.r_number >> s.grade;s.l_number = i + 1;      //考场号按照升序自动升,第一个输入的就是1考场,第二个输入就是2考场stu[R++] = s;}sort(stu + SUM, stu + SUM + K, cmp);stu[SUM].l_rank = 1;for (int i = SUM + 1; i < SUM + K; i++){if (stu[i].grade == stu[i - 1].grade) stu[i].l_rank = stu[i - 1].l_rank;else stu[i].l_rank = i - SUM + 1;}SUM += K;}sort(stu, stu + SUM, cmp);int r = 1;cout << SUM << endl;for (int i = 0; i < SUM; i++){if (i>0 && stu[i].grade != stu[i - 1].grade){r = i + 1;}cout << stu[i].r_number << " " << r << " " << stu[i].l_number << " " << stu[i].l_rank << endl;}return 0;
}

编程中有可能遇到的小问题(必看!可能你代码过不了是因为它!)

  1. 审题问题:由于英文题目,第一次写的时候看的太粗略,没看见如果分数相同则按照准考证号升序排列
  2. 内存问题:由于数组的大小是30010,非常大,我记得好像在main函数里面定义使用的是系统栈,可能导致溢出(我就遇到了),所以应该定义为全局变量(划重点!!!

水平有限,如果代码有任何问题或者有不明白的地方,欢迎在留言区评论;也欢迎各位大牛提出宝贵的意见!

[PAT A1025]PAT Ranking相关推荐

  1. PAT A1141 PAT Ranking of Institutions ——昨夜西风凋碧树

    PAT A1141 PAT Ranking of Institutions 中间计算TWS时不能使用int,否则最后一个测试点不过.但是比较和输出又需要用int,在里面强转int也不给AC,无奈只好先 ...

  2. 17冬第二题 PAT甲级 1141 Ranking of Institutions (25分) 有点鸡贼

    题目 After each PAT, the PAT Center will announce the ranking of institutions based on their students' ...

  3. 【置顶】【PAT】PAT甲级题目及分类总结(持续更新ing)

    在2019年3月底,我决定考浙大计院,经过一个月还算凑合的学习,痛定思痛,决定整理整理自己的博客. 粗略估计,大概一个月的时间里我AC了31道题,大概用时40个小时上下,毕竟还要把大部分时间花在笔试上 ...

  4. 算法笔记 P103 例题:【PAT A1025】PAT Ranking

    题目链接 题目 Programming Ability Test (PAT) is organized by the College of Computer Science and Technolog ...

  5. PAT 1025 PAT Ranking题解

    大致题意: 输入所有考生的考号以及所有考生的成绩,以及考生所在的考场号. 输出格式: 考生的考场号 考生的总名次 考生所在的考场号 考生所在考场的名次 首先解决考生的排名问题,应当先对考生在本考场所取 ...

  6. PAT 1085 PAT单位排行(25)(映射、集合训练)

    1085 PAT单位排行(25 分) 每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数 N(≤10​5​​),即考生人数.随 ...

  7. PAT 1025 PAT Rankings 思路与题解

    1025 PAT Ranking 原题 思路 定义结构体,将分考场排名也纳入结构体内 id以字符数组的形式存储,输入输出均用格式控制符%s即可 化繁为简,通过下标灵活控制多个一维数组的组合.不要轻易考 ...

  8. 1040 有几个PAT(PAT乙级 C++)

    题目 字符串 APPAPT 中包含了两个单词 PAT,其中第一个 PAT 是第 2 位(P),第 4 位(A),第 6 位(T):第二个 PAT 是第 3 位(P),第 4 位(A),第 6 位(T) ...

  9. PAT 1085. PAT单位排行 (25) - 乙级

    每次 PAT 考试结束后,考试中心都会发布一个考生单位排行榜.本题就请你实现这个功能. 输入格式: 输入第一行给出一个正整数N(<=105),即考生人数.随后N行,每行按下列格式给出一个考生的信 ...

最新文章

  1. 批处理获取目录下所有文件名
  2. 工业红外温度传感器 测温探头在线式4-20mA 变送器红外线非接触式
  3. 在Sharepoint中批量删除大量条目
  4. 按字段顺序加载或解析JSON对象
  5. VC++ 多线程同步实例
  6. 蔚来发布首款自动驾驶车型ET7 补贴前起售价44.8万元
  7. [BZOJ2038]小Z的袜子(莫队算法)
  8. 《魔鬼搭讪学》读书笔记
  9. 东方通TongWeb启动springboot报错
  10. MacBook 快捷键个人总结和设置
  11. 程序员分哪几种?分别要学什么知识?工资怎么样?
  12. 移动CMPP3.0短信网关接口协议
  13. 码云Gitee WebHook Jenkins 403 err:No valid crumb was included in the request
  14. BigDecimal ROUND_HALF_DOWN精度问题
  15. 中首清算质疑偶像演员不适合演抗战剧?《雷霆战将》三大还原引争议
  16. Latex技巧:LaTex插图命令includegraphics参数详解
  17. Chicken first or egg?
  18. C++ list initialization
  19. BATT集体发力搜索,争夺下一代搜索平台的“引路人”
  20. Linux中 ifconfig命令只有lo没有eth0/ens33

热门文章

  1. tkinter 可用字体颜色汇总
  2. 怎么看待软件测试这些软实力?
  3. 计算机无法识别ek-gc100,EK-GC100相机
  4. Win10进不去,卡在欢迎界面
  5. 上传Android程序到应用市场
  6. Windows10 右击win标(或win+x快捷键)无反应的解决方法(开始菜单)
  7. JSP基于网络超市商品销售管理系统的设计与实现(源代码+论文)
  8. Java语言进阶-List、Set、数据结构、Collections
  9. Bert:一切过往,皆为序章
  10. bit和bytes(ZT)