题目

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 Algebra), 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

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

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


题解

#include<cstdio>
#include<algorithm>
using namespace std;
struct student{int id;int score[4];//每个人每门课的分数,每门课的排名
}stu[2010];int Rank[1000000][4]={0};//初始化排名为0
int course;
bool cmp(student a,student b){return a.score[course]>b.score[course];
}
char k[4]={'A','C','M','E'};int main(){int n,m;int q;scanf("%d %d",&n,&m);for(int i=0;i<n;i++){scanf("%d%d%d%d",&stu[i].id,&stu[i].score[1],&stu[i].score[2],&stu[i].score[3]);stu[i].score[0]=stu[i].score[1]+stu[i].score[2]+stu[i].score[3];//0A,1C,2M,3E}for(course=0;course<4;course++){//判断哪个哪个就放外循环,这边不能写成int courese因为变量已定义,是同一变量sort(stu,stu+n,cmp);//分别排了4个成绩的序 应该得出四个结点,而不单单是分数Rank[stu[0].id][course]=1;//与库中元素重名for(int j=1;j<n;j++){if(stu[j].score[course]==stu[j-1].score[course]){Rank[stu[j].id][course]= Rank[stu[j-1].id][course];}else Rank[stu[j].id][course]=j+1;//=号右边原来是错误的}}for(int i=0;i<m;i++){scanf("%d",&q);if(Rank[q][0]==0) printf("N/A\n");else{int temp=0;for(int i=0;i<4;i++){if(Rank[q][i]<Rank[q][temp])temp=i;//选出被查询学生4科中排名最前的一科}printf("%d %c\n",Rank[q][temp],k[temp]);}}return 0;
}

这里犯了数组名不能与库函数同名,已定义的同一变量不能再声明的错误。以及一开始没有意识到结构体排序是排得结点。还有bool函数的参数里应写结构体的本名,而不是引用名。

以及排序到了第3个人,他应该就是第3名,而不是前面并列的名次+1。

PAT甲级1012 (结构体,排序)相关推荐

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

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

  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. qvector 结构体排序_C++结构体的应用_YCOJ

    结构体是一种自定义的东西,用struct来定义.在他里面, 可以装许多东西,比如int,string,char,bool等等等等. 如: struct a{ string name; int a; i ...

  5. 还是贪心(结构体排序)

    2128: 盾神与积木游戏 Time Limit: 1 Sec Memory Limit: 128 MB Submit: 127 Solved: 39 [Submit][Status][Web Boa ...

  6. sort对结构体排序

    1.排序方法: sort(数组起始指针,数组尾指针,排序规则); 数组起始指针,数组尾指针是左闭右开 排序规则可以省略,也可以用系统的,也可以自己写 2.例子: int a[]={9,2,4,5,10 ...

  7. P1068 分数线划定 洛谷 (C++)(结构体排序)

    简单的结构体排序,代码如下 #include <iostream> #include <cstdio> #include <algorithm> #include ...

  8. C#中结构体排序方法(Array.sort() + ICompare)

    感觉C#比C++麻烦许多,资料也少,找了半天竟然没有找到一个能用的结构体排序. 这是待排序的结构体: public struct la{public int id;public int sb;}; 首 ...

  9. 【HDU】1862 EXCEL排序(结构体排序)

    Problem Description Excel可以对一组纪录按任意指定列排序.现请你编写程序实现类似功能. Input 测试输入包含若干测试用例.每个测试用例的第1行包含两个整数 N (<= ...

最新文章

  1. linux内核定义的常用信号6,Linux中的信号
  2. Linux那些事儿 之 戏说USB(11)繁华落尽
  3. 网络工程师计算机类吗,机房网络工程师 | 网络工程专业的你知道吗?
  4. Jetty 基本使用样例
  5. 比亚迪f3android系统,比亚迪F3发动机防盗系统设定
  6. 史上最详细“截图”搭建Hexo博客——For Windows
  7. jinja2 {{}} href 双大括号
  8. 从零开始做一个SLG游戏(二):用mesh实现简单的地形
  9. net发布的dll方法和类显示注释信息(字段说明信息)[图解]
  10. Image:介绍一些跟图片有关的控件,如图片展示特效,图片生产,图片保护等
  11. mysql故障切换_MySQL故障切换笔记之应用无感知设计详解
  12. 获取Button脚本挂载的事件名
  13. 51nod1127 最短的包含字符串
  14. python图像识别植物识别_python 植物识别 error_code
  15. 编码解码--url编码解码
  16. New UI-常用计量单位px,dp,sp,pt解析与转换
  17. win10 远程桌面和向日葵远控哪个好用
  18. mining.subscribe与initiate_stratum函数
  19. 笔记本 服务器 性能,笔记本CPU性能天梯图2021最新6月
  20. linux中python怎么退出_linux 怎么退出python

热门文章

  1. c语言dfs算法,DFS算法源程序
  2. mysql下删改增语句_MySQL增删改查
  3. mysql sqlserver alter语句区别_SQL ALTER
  4. 文都计算机考研辅导班哪个好,考研辅导班哪个好,海文还是文都?
  5. java语言cd_java语言
  6. java 中 class 对象_java中Class对象详解
  7. HALCON 20.11:深度学习笔记(7)---术语表
  8. Visual Studio 2017在编译OpenCV 4.2.0时出现编译器错误C2001:常量中有换行符
  9. python使用opencv保存视频_Pythone OpenCV学习笔记之:视频文件读取与保存
  10. 2.4 Python 模块的使用安装导入