To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematics (Calculus or Linear Algrbra), and E - English. At the mean time, we encourage students by emphasizing on their best ranks -- that is, among the four ranks with respect to the three courses and the average grade, we print the best rank for each student.

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 (≤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.

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:

  1. 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:
  1. 2
  2. 5
  3. 1234567890001 95
  4. 1234567890005 100
  5. 1234567890003 95
  6. 1234567890002 77
  7. 1234567890004 85
  8. 4
  9. 1234567890013 65
  10. 1234567890011 25
  11. 1234567890014 100
  12. 1234567890012 85
Sample Output:
  1. 9
  2. 1234567890005 1 1 1
  3. 1234567890014 1 2 1
  4. 1234567890001 3 1 2
  5. 1234567890003 3 1 2
  6. 1234567890004 5 1 4
  7. 1234567890012 5 2 2
  8. 1234567890002 7 1 5
  9. 1234567890013 8 2 3
  10. 1234567890011 9 2 4
思路
  • 每次读进来一组数据就进行一次排序,同时要注意相同分数的情况下排名要顺延,也就是说100 95 95 85 77对应的名次是1 2 2 4 5
代码
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. struct node
  4. {
  5. char id[15];
  6. int score;
  7. int loc; //location
  8. int loc_rank;
  9. int all_rank;
  10. }a[30010];
  11. int a_num = 0;
  12. bool cmp(node a, node b)
  13. {
  14. if(a.score != b.score)
  15. return a.score > b.score;
  16. else return strcmp(a.id, b.id) < 0;
  17. }
  18. int main()
  19. {
  20. int cases;
  21. scanf("%d", &cases);
  22. int cnt = 0;
  23. int level = 1;
  24. int n;
  25. while(cases--)
  26. {
  27. scanf("%d", &n);
  28. for(int j=0;j<n;j++)
  29. {
  30. scanf("%s %d", a[a_num].id, &a[a_num].score);
  31. a[a_num].loc = level;
  32. a_num++;
  33. }
  34. sort(a + cnt, a + cnt + n, cmp);
  35. a[cnt].loc_rank = 1;
  36. for(int i=cnt+1;i<cnt+n;i++)
  37. {
  38. if(a[i].score == a[i-1].score)
  39. a[i].loc_rank = a[i-1].loc_rank;
  40. else
  41. a[i].loc_rank = i - (cnt + 1) + 2;
  42. }//对每个loc进行单独的排序
  43. cnt += n;
  44. level++;
  45. }
  46. sort(a, a + a_num, cmp);
  47. a[0].all_rank = 1;
  48. for(int i=1;i<a_num;i++)
  49. {
  50. if(a[i].score == a[i-1].score)
  51. a[i].all_rank = a[i-1].all_rank;
  52. else
  53. a[i].all_rank = i + 1;
  54. }
  55. printf("%d\n", cnt);
  56. for(int i=0;i<a_num;i++)
  57. {
  58. printf("%s %d %d %d\n", a[i].id, a[i].all_rank, a[i].loc, a[i].loc_rank);
  59. }
  60. return 0;
  61. }
引用

<https://pintia.cn/problem-sets/994805342720868352/problems/994805474338127872P

PTA(Advanced Level)1025.PAT Ranking的更多相关文章

  1. PAT (Advanced Level) 1025. PAT Ranking (25)

    简单题. #include<iostream> #include<cstring> #include<cmath> #include<algorithm> ...

  2. PTA(Advanced Level)1075.PAT Judge

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  3. 1025 PAT Ranking[排序][一般]

    1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer S ...

  4. PAT 甲级 1025 PAT Ranking

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  5. 1025 PAT Ranking (25分)

    1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 ...

  6. PAT甲级——1025 PAT Ranking

    1025 PAT Ranking Programming Ability Test (PAT) is organized by the College of Computer Science and ...

  7. PAT甲级:1025 PAT Ranking (25分)

    PAT甲级:1025 PAT Ranking (25分) 题干 Programming Ability Test (PAT) is organized by the College of Comput ...

  8. PTA(Advanced Level)1036.Boys vs Girls

    This time you are asked to tell the difference between the lowest grade of all the male students and ...

  9. 【PAT】1025. PAT Ranking (25)

    题目链接:http://pat.zju.edu.cn/contests/pat-a-practise/1025 题目描述: Programming Ability Test (PAT) is orga ...

随机推荐

  1. parents([expr]) 取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素)。可以通过一个可选的表达式进行筛选。

    parents([expr]) 概述 取得一个包含着所有匹配元素的祖先元素的元素集合(不包含根元素).可以通过一个可选的表达式进行筛选.大理石平台检定规程   参数 exprStringV1.0 用于 ...

  2. js上传文件夹

    用过浏览器的开发人员都对大文件上传与下载比较困扰,之前遇到了一个php文件夹上传下载的问题,无奈之下自己开发了一套文件上传控件,在这里分享一下.希望能对你有所帮助.此控件PC全平台支持包括mac,li ...

  3. luogu 3047 [USACO12FEB]附近的牛Nearby Cows 树形dp

    $k$ 十分小,直接暴力维护 $1$~$k$ 的答案即可. 然后需要用父亲转移到儿子的方式转移一下. Code: #include <bits/stdc++.h> #define M 23 ...

  4. P2699 【数学1】小浩的幂次运算

    原题链接 https://www.luogu.org/problemnew/show/P2699 P2699 [数学1]小浩的幂次运算 首先第一眼看这个题就知道要暴力枚举w^i 看是否在区间[l,r] ...

  5. python基本数据类型剖析

    一. 基本数据类型常用功能:1. 整数 int #int内部优化 n1=123 n2=n1 n1= 123 n2= 123 ========2份内存========= if -5~257: n1= 1 ...

  6. ACM之路(17)—— 博弈论

    博弈论这方面网上资料庞大,我觉得我不可能写的比他们好,就转载一下我觉得写的不错的博客好了. 首先是三大博弈:巴什博奕,威佐夫博奕,尼姆博奕.博客:三大基本博弈. 然后是强大的sg函数和sg定理:SG. ...

  7. Tomcat的server.xml

    慕课网:https://www.imooc.com/video/19201 Server:指整个tomcat服务器,它其中包含多个组件,它主要负责管理和启动各个service,同时监听8005端发过来 ...

  8. java按某个字段对数据分组

    import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; i ...

  9. Leetcode题目121.买卖股票的最佳时机(简单)

    题目描述: 给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格. 如果你最多只允许完成一笔交易(即买入和卖出一支股票),设计一个算法来计算你所能获取的最大利润. 注意你不能在买入股票前卖出 ...

  10. Linux: Block Port With IPtables

    由Internet和其他网络协议识别端口号,使计算机能够与其他人进行交互.每个Linux服务器都有一个端口号(参见/ etc / services文件) Block Incoming Port The ...