PAT甲级 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

我用了两个结构体,不熟练的也可以用二维数组,具体注释放代码里了,一开始21分,后来看了大神的解释懂了,不同人的名次可能相同,之后的名次不能顺延,需要跳位,例如:

90 88 88 75

排名应该为:

1 2 2 4

PAT是真的考验代码的严谨性,AC代码如下:

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e3+5;struct Rank{char c;//分数对应的科目int score,r;//分数和该分数所在排名
};struct node{string id;Rank s[4];//四门科目成绩
}stu[N];bool cmp1(node a,node b){//比较‘A’科目的成绩return a.s[0].score>b.s[0].score;
}bool cmp2(node a,node b){//比较‘C’科目的成绩return a.s[1].score>b.s[1].score;
}bool cmp3(node a,node b){//比较‘M’科目的成绩return a.s[2].score>b.s[2].score;
}bool cmp4(node a,node b){//比较‘E’科目的成绩return a.s[3].score>b.s[3].score;
}bool cmp5(Rank a,Rank b){//比较每门成绩的排名if(a.r!=b.r) return a.r<b.r;else return a.c<b.c;//若排名相同则比较科目优先级
}int main(){int n,q;cin>>n>>q;for(int i=0;i<n;i++){cin>>stu[i].id>>stu[i].s[1].score>>stu[i].s[2].score>>stu[i].s[3].score;stu[i].s[0].score=(stu[i].s[1].score+stu[i].s[2].score+stu[i].s[3].score)/3;}sort(stu,stu+n,cmp1);for(int i=0;i<n;i++){if(i==0) stu[i].s[0].r=i+1;else if(i>0){if(stu[i].s[0].score==stu[i-1].s[0].score) stu[i].s[0].r=stu[i-1].s[0].r;else stu[i].s[0].r=i+1;}stu[i].s[0].c='A';}sort(stu,stu+n,cmp2);for(int i=0;i<n;i++){if(i==0) stu[i].s[1].r=i+1;else if(i>0){if(stu[i].s[1].score==stu[i-1].s[1].score) stu[i].s[1].r=stu[i-1].s[1].r;else stu[i].s[1].r=i+1;}stu[i].s[1].c='C';}sort(stu,stu+n,cmp3);for(int i=0;i<n;i++){if(i==0) stu[i].s[2].r=i+1;else if(i>0){if(stu[i].s[2].score==stu[i-1].s[2].score) stu[i].s[2].r=stu[i-1].s[2].r;else stu[i].s[2].r=i+1;}stu[i].s[2].c='M';}sort(stu,stu+n,cmp4);map<string,int>m,M;//m存id对应的下标,M判断id是否合法for(int i=0;i<n;i++){if(i==0) stu[i].s[3].r=i+1;else if(i>0){if(stu[i].s[3].score==stu[i-1].s[3].score) stu[i].s[3].r=stu[i-1].s[3].r;else stu[i].s[3].r=i+1;}stu[i].s[3].c='N';//我将E先改成M,方便以A-C-M-N的顺序排序比较m[stu[i].id]=i;M[stu[i].id]=1;}string id;while(q--){cin>>id;if(M[id]==0) puts("N/A");else{sort(stu[m[id]].s,stu[m[id]].s+4,cmp5);//比较排名if(stu[m[id]].s[0].c=='N') {stu[m[id]].s[0].c='E';cout<<stu[m[id]].s[0].r<<" "<<stu[m[id]].s[0].c<<endl;}else cout<<stu[m[id]].s[0].r<<" "<<stu[m[id]].s[0].c<<endl;}}
}

PAT甲级 1012 The Best Rank相关推荐

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

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

  2. PAT 甲级 1012 The Best Rank

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

  3. 【PAT - 甲级1012】The Best Rank (25分)

    题干: To evaluate the performance of our first year CS majored students, we consider their grades of t ...

  4. PAT甲级1012:The Best Rank (25)

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

  5. PAT甲级1012 (结构体,排序)

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

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

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

  7. PAT 1012 The Best Rank (25 分)

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

  8. PAT 1012 The Best Rank

    参考自: https://www.nowcoder.com/questionTerminal/5a5281aef52a4f6f943929c05ba71c11 题目链接: 1012 The Best ...

  9. PAT甲级真题目录(按题型整理)(转自柳神)

    转载自:https://www.liuchuo.net/archives/2502?tdsourcetag=s_pcqq_aiomsg 最短路径 1003. Emergency (25)-PAT甲级真 ...

  10. PAT甲级训练合集(1-70)

    本章题解跳转 考点 P1001 数字的数组表示和处理 P1002 多项式的数组表示和处理 P1003 深度优先搜素 P1004 深度优先搜素 P1005 哈希表 P1006 P1007 数组子区间求和 ...

最新文章

  1. 在Android中使用Handler和Thread线程执行后台操作
  2. 二十五、redis主从复制
  3. python使用matplotlib的savefig保存时图片保存不完整的问题
  4. 中国5G标准专利数量遥遥领先:不卖产品也获利
  5. 设计模式 C++简单工厂模式
  6. IOS绘制渐变背景色折线图的一种尝试
  7. 《TensorFlow 2.0深度学习算法实战教材》学习笔记(四、TensorFlow 进阶)
  8. webuploader
  9. 短信平台API接口集成指南
  10. bpsk调制rician_fading信道的simulink仿真
  11. FLUKE754连接电脑hart协议操作指南
  12. php调用winhttp,HTTP HTTPS POST GET(包含curl版本和winhttp两种实现)
  13. JNI/NDK入门指南之JavaVM和JNIEnv
  14. 在线教育开源源码:线上教育如今各种“陷阱营销”,应如何规避?
  15. ASP.NET MVC后台判断是否是手机登录以及是否是微信公众号登陆
  16. UPC9575 鑫鑫的算术
  17. 10个屌炸天的设计网址导航带你嗨翻科技设计界 #精选前端开发设计素材
  18. R语言和Python实现分数次幂微积分计算(主要是Python)
  19. 东莞潇洒老师:分享PROE产品设计塑胶产品结构基本设计
  20. android自定义金额输入键盘_触摸键盘的设计解析

热门文章

  1. 三月校赛1006 wuli通通和Fibonacci (a[n]=f[n]*(n^m)的前k项和)
  2. doxygen 注释规范_Doxygen简明注释语法
  3. 电脑重启桌面 计算机图标消失,电脑重启后计算机图标不见了怎么办
  4. 100-1000的水仙花数 有哪些?
  5. Internet Explorer之后的前端开发
  6. VMware虚拟机不能上网了怎么办
  7. WINDOWS 7、windows server 2008、VISTA激活排斥
  8. begin tran创建事务、commit tran提交事务、rollback tran回滚(撤消)事务的用法及理解
  9. 惊恐!监控拍到神秘人形机器人凌晨三点出逃
  10. CorelDRAW X8最新版本安装使用教程