参考自:
https://www.nowcoder.com/questionTerminal/5a5281aef52a4f6f943929c05ba71c11
题目链接:
1012 The Best Rank
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.

For example, The grades of C, M, E and A - Average of 4 students are given as the following:

StudentID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91
Then the best ranks for all the students are No.1 since the 1st one has done the best in C Programming Language, while the 2nd one in Mathematics, the 3rd one in English, and the last one in average.

Input Specification:
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤2000), which are the total number of students, and the number of students who would check their ranks, respectively. Then N lines follow, each contains a student ID which is a string of 6 digits, followed by the three integer grades (in the range of [0, 100]) of that student in the order of C, M and E. Then there are M lines, each containing a student ID.

Output Specification:
For each of the M students, print in one line the best rank for him/her, and the symbol of the corresponding rank, separated by a space.

The priorities of the ranking methods are ordered as A > C > M > E. Hence if there are two or more ways for a student to obtain the same best rank, output the one with the highest priority.

If a student is not on the grading list, simply output N/A.

Sample Input:

5 6
310101 98 85 88
310102 70 95 88
310103 82 87 94
310104 91 91 91
310105 85 90 90
310101
310102
310103
310104
310105
999999

Sample Output:

1 C
1 M
1 E
1 A
3 A
N/A

解题思路:
只说坑点,
(1)该题数据中id均为数字,不含其它字符(用int即可,可以用hash的思想开辟一个大的空间,最后判断id是否出现)
(2)注意到相同的分是一个名次
(3)注意不要用多个结构体来存信息,容易爆内存…
(4)rank在PAT系统里面是关键字…用Rank代替…
(5)胆大心细:)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxv=1000000;
int Rank[maxv][4];
struct stu{//  char id[100];int id;int score[4];
}a[maxv];
int p=0;
char lecture[]={'A','C','M','E'};
bool cmp(stu &a1,stu &a2){return a1.score[p]>a2.score[p];
}
int main(){int n,m;scanf("%d%d",&n,&m);for(int i=0;i<n;i++){scanf("%d%d%d%d",&a[i].id,&a[i].score[1],&a[i].score[2],&a[i].score[3]);a[i].score[0]=a[i].score[1]+a[i].score[2]+a[i].score[3];}memset(Rank,0,sizeof(Rank));for(int i=0;i<4;i++){//科目 sort(a,a+n,cmp);Rank[a[0].id][i]=1;for(int k=1;k<n;k++){//人数 if(a[k].score[i]==a[k-1].score[i])  Rank[a[k].id][i]= Rank[a[k-1].id][i];//相同分数 else{Rank[a[k].id][i]=k+1;}}p++;}while(m--){int id;scanf("%d",&id);if(!Rank[id][0]) {printf("N/A\n");continue;}int _min=0x7ffffff,_ind=-1;for(int k=0;k<4;k++){if(Rank[id][k]<_min){_min=Rank[id][k];_ind=k;}}printf("%d %c\n",_min,lecture[_ind]);}return 0;
}

PAT 1012 The Best Rank相关推荐

  1. PAT 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) 今天给大家分享的是PAT甲级的一道小题,设计题 原题请点击我 简单翻译: 设计一个排名表,这个表中以学生ID为主键,C表示程序设计语言的成绩,M表示 ...

  2. PAT甲级1012 The Best Rank :[C++题解]4个成绩取排名最低:排序、二分(好题)

    文章目录 题目分析 题目链接 题目分析 遇到的问题:信息存在结构体(✖)中,然后排名呢?需要分别对 C.M.E.A排四次吗? 这里成绩的存储 用二维数组 vector<int> q[4]; ...

  3. PAT 甲级 1012 The Best Rank

    PAT 甲级 1012 The Best Rank To evaluate the performance of our first year CS majored students, we cons ...

  4. PAT甲级真题(结构体排序)——1012. The Best Rank (25)

    1012. The Best Rank (25) To evaluate the performance of our first year CS majored students, we consi ...

  5. 【PAT甲级 排序】1012 The Best Rank (25 分) C++ 全部AC

    题目 中规中矩的一道题.排名的顺序一开始没太明白,但是理解之后写起来挺流畅的,没什么坑. 解题思路:题目会给出所有学生所有科目的成绩.想要看分学生的学号. 我们要先给这些学生单科成绩排序,算出它们的单 ...

  6. 【解析】1012 The Best Rank (25 分)

    立志用最少的代码做最高效的表达 PAT甲级最优题解-->传送门 To evaluate the performance of our first year CS majored students ...

  7. 1012 The Best Rank (25)

    题目描述: To evaluate the performance of our first year CS majored students, we consider their grades of ...

  8. 1012 The Best Rank

    思路:读入全部的数据之后,按照四个cmp函数对数组进行排序,给每生的4个科目的排名赋值,读入要检验的id后使用strcmp对数组中的id进行遍历(幸好这里数组大小和要检验的数目乘积不超过4万),如果找 ...

  9. 1012 The Best Rank (25 分)【难度: 中 / 知识点: 排序 前缀和】

    https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480 解析: 这里的每一项排名有一个坑的点,就是 ...

最新文章

  1. 如何学习streamdecoder类_如何学习篇5:强化2种能力——2种学习模式之运动类:隐性学习...
  2. 重要通知:招募200程序员,免费培训金融知识,不限年龄,有意者进!
  3. SAP PM创建多语言文本
  4. php ajax 点击后刷新当前页面,ajax请求值后返回会刷新页面?
  5. QDoc文字标记textmarkup
  6. Android 沉浸式透明状态栏与导航栏
  7. 【C++进阶】利用重载二元运算符改进平面向量类Vec2D
  8. 【C#】wpf自定义calendar日期选择控件的样式
  9. maven设置从本地读_如何在Eclipse中更改Maven本地存储库
  10. 搜狐畅游一面(c++)
  11. 硕士阶段学习情况汇总
  12. VSCode(Visual Studio Code) 在Python中,自动提示函数选中后带括号设置
  13. Py西游攻关之基础数据类型
  14. 【错误解决】SpringBoot邮件服务的一些错误及其解决方案
  15. 做为一个好人 你应该看这部电影
  16. 如何使用电脑将图片进行压缩?图片压缩软件怎么操作?
  17. Ckp的约会(xmu oj)贪心算法问题 by C++
  18. OA是什么?对企事业单位的发展起何作用?
  19. 吃一堑长一智!带你快速通过字节跳动面试,知乎上转疯了!
  20. Java学习_Day003

热门文章

  1. Java中求一个数的幂次方
  2. cmd的发送 mmc_【翻译】如何使用MMC/SD卡
  3. 制作一个月球车底盘【内附资料下载链接】
  4. 【运维监控】四款云服务监控工具介绍:Nagios 、 ganglia、zabbix、onealert
  5. 分页(Limit+RowBounds)
  6. 带你真正认识 Linux 系统结构
  7. windows7 校验下载文件的sha512
  8. SDL_Surface表面
  9. DNS解析过程(windows系统举例)
  10. K-means和KNN