1012 The Best Rank (25)(25 分)

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

//emm,这个没写出来,看了别人的之后恍然大悟,我应该过几天之后再自己写出来。

代码来自:https://www.liuchuo.net/archives/2207

#include <cstdio>
#include <algorithm>
using namespace std;
struct node {
int id, best;
int score[], rank[];
}stu[];
int exist[], flag = -;//厉害了,不用map,用哈希数组。
bool cmp1(node a, node b) {return a.score[flag] > b.score[flag];}
//我的天,这个flag可以默认传进来。。
int main() {
int n, m, id;
scanf("%d %d", &n, &m);
for(int i = ; i < n; i++) {
scanf("%d %d %d %d", &stu[i].id, &stu[i].score[], &stu[i].score[], &stu[i].score[]);
stu[i].score[] = (stu[i].score[] + stu[i].score[] + stu[i].score[]) / 3.0 + 0.5;
//要四舍五入,所以+0.5后取整。
}
for(flag = ; flag <= ; flag++) {
sort(stu, stu + n, cmp1);
//有可能按照这个排出来之后,连续好几个数都相等。
stu[].rank[flag] = ;
for(int i = ; i < n; i++) {
stu[i].rank[flag] = i + ;//理论上来说先赋值为i+1,再判断和前边相等,那么就再更新。
if(stu[i].score[flag] == stu[i-].score[flag])
stu[i].rank[flag] = stu[i-].rank[flag];//那么就直接赋值相等就可以了。
}
}
for(int i = ; i < n; i++) {
exist[stu[i].id] = i + ;
stu[i].best = ;
int minn = stu[i].rank[];
for(int j = ; j <= ; j++) {//这个也是通过循环找到。
if(stu[i].rank[j] < minn) {
minn = stu[i].rank[j];
stu[i].best = j;
}
}
}
char c[] = {'A', 'C', 'M', 'E'};
for(int i = ; i < m; i++) {
scanf("%d", &id);
int temp = exist[id];
if(temp) {
int best = stu[temp-].best;
printf("%d %c\n", stu[temp-].rank[best], c[best]);
} else {
printf("N/A\n");
}
}
return ;
}

//看这个代码受到了很多启发:1.如果出现分数名相等的情况,该怎么处理?for循环写的非常好,并且根据题目特点使用了哈希数组存储id对应的下标,但是因为牛客网上的id中包含字母,所以就通不过,这个地方可以改进,明天我来试一试。

PAT The Best Rank[未作]的更多相关文章

  1. PAT Battle Over Cities [未作]

    1013 Battle Over Cities (25)(25 分) It is vitally important to have all the cities connected by highw ...

  2. PAT A1012 Best Rank(25)

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

  3. PAT甲级 并查集 相关题_C++题解

    并查集 PAT (Advanced Level) Practice 并查集 相关题 <算法笔记> 重点摘要 1034 Head of a Gang (30) 1107 Social Clu ...

  4. 借助Process Explorer定位断电未保存的录音文件

    话说某大神(大婶)开会常偷懒,用Windows自带的录音机进行录音并用记事本记录会议精要却没有点击Ctrl+S的习惯,结果就给我找了今天的难题.(之前都是Office的自动保存在哪里……) 还是一样, ...

  5. Java & Android未捕获异常处理机制

    一.背景 无论是Java还是Android项目,往往都会用到多线程.不管是主线程还是子线程,在运行过程中,都有可能出现未捕获异常.未捕获异常中含有详细的异常信息堆栈,可以很方便的去帮助我们排查问题. ...

  6. PAT(B) 1059 C语言竞赛(C)

    题目链接:1059 C语言竞赛 (20 point(s)) 题目描述 C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛.既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: 冠军将赢得一份" ...

  7. PAT题目AC汇总(待补全)

    题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...

  8. 未释放资源的教训,开发MongoDB连接一定要关闭连接

    废不少工夫将数据存储,全部迁移至mongodb,未作大量改动则是主因. 但遇到奇怪的现象. 程序跑起不久后,mongodb即假死,另起客户端想登陆mongodb都不成. 要重启mongodb服务器才好 ...

  9. 转债---Pregel: A System for Large-Scale Graph Processing(译)

    转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/   作者:Grzegorz Malewicz, Matthew ...

随机推荐

  1. 【前端系列】移动前端开发之viewport的深入理解

    在页面上没有设置width所以样式显示有问题,本来选择的响应式模式的320*410结果看到页面的实际宽度确实980px. 本文转载自: 在移动设备上进行网页的重构或开发,首先得搞明白的就是移动设备上的 ...

  2. MacOS 安装PyQt5

    PyQt5官方安装教程指出2种安装方法: Installing from Wheels Building and Installing from Source 网上搜罗的大多是按照第二种方法安装的,本 ...

  3. LinQ实战学习笔记(二) C#增强特性

    C# 为支持LINQ添加了许多语言特性: 隐式类型局部变量 对象初始化器 Lambda表达式 扩展方法 匿名类型 了解这些新特性是全面了解LINQ的重要先解条件,因此请不要忽视它们. (一)  隐式类 ...

  4. jQuery mobile 初始化页面的过程

  5. 查看运行中的Java其配置的堆大小

    一.背景 有题目中的需求,也不是空穴来风:前一阵给公司搭建了一个持续集成服务器,Jenkins.最近发现,运行一段时间后,就变慢了. 随便一个操作,cpu就飙高了.然后就思考会不会是内存不够用,频繁G ...

  6. browsersync即时刷新页面

    Browsersync能让浏览器实时.快速响应您的文件更改(html.js.css.sass.less等)并自动刷新页面 官网: http://browsersync.cn/ 多个浏览器.多个设备间来 ...

  7. 静态时序分析基础STA

    静态时序分析SAT   1.   背景 静态时序分析的前提就是设计者先提出要求,然后时序分析工具才会根据特定的时序模型进行分析,给出正确是时序报告. 进行静态时序分析,主要目的就是为了提高系统工作主频 ...

  8. 关于Nagios通过NRPE监控客户端的安装与配置

    环境介绍>>>>>>>>>>>>>>>>>>>>>>>> ...

  9. nagios监控报错 It appears as though you do not have permission to view...

    今天在安装完nagios后,通过nagios网页界面点击主机.服务.问题页面时.均报错,报错的内容都差不多.如点击服务,报错: It appears as though you do not have ...

  10. python nose测试框架全面介绍八---接口测试中非法参数的断言

    在测接口时,会有这样的场景,输入非法的参数,校验返回的错误码及错误内容 通常做法为发请求,将错误的返回结果拿出,再进行对比匹配:但存在一个问题,需要再写错误返回分析函数,不能与之前正常发请求的函数共用 ...