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. Delphi XE4 For IOS之部署问题
  2. 手机端自适应字体大小和元素宽度自适应
  3. HTMLTestRunner 为什么用PyCharm(Eclipse)执行测试成功但无法生成报告
  4. 【视频课】先搞懂你用的模型,深度学习模型分析课程来了!
  5. docker快速入门01——docker安装与简单应用
  6. 面试官:你对MySQL高性能优化有什么规范建议?
  7. win7电脑共享硬盘分区的方法
  8. c# 批量mqtt_C#使用 MQTTnet 快速实现 MQTT 通信(文末有完整Demo下载)
  9. mysql 清理 reley_MySQL日志相关
  10. Codeforces 808G. Anthem of Berland
  11. 蓝桥杯——基础练习之字母图形
  12. 概率论 - 常见分布(及其分布表)
  13. Allatori:代码混淆器的使用(EclipseIDEA)
  14. 13.图像识别与文字处理
  15. 【Paper Reading】Improving Availability of Vertical Federated Learning Relaxing Inference on Non-overl
  16. 二进制、十进制、八进制、十六进制 各代表的英文字母是什么
  17. EDI REMADV报文详解
  18. 什么是B2B,B2C,C2C?
  19. CentOS 7安装Docker
  20. 为Linux发行版安装中文字体

热门文章

  1. 泰晤士报华科计算机排名,最新USNews中国内地高校计算机学科排名,北大第7,华科第2?...
  2. facebook登陆授权 服务器接入记录
  3. 基于业务流程管理框架的企业敏捷性研究
  4. 【数学】通俗解释布丰投针实验过程、蒙特卡洛方法及python仿真代码
  5. kgm转mp3安卓_酷狗KGM转MP3格式工具电脑版
  6. 【Spring】源码浅析 - ResponseEntity.ok
  7. ROS学习:launch文件编写
  8. FIFO读数据异常分析
  9. DNS服务器可能不可用的解决方法
  10. 【云计算学习教程】探讨私有云计算平台的搭建(附带3套解决方案)