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. webapck html-loader实现资源复用

    1.安装 npm i html-loader --save-dev 2.项目目录 layout文件夹下的footer.html文件为: <script type="text/javas ...

  2. mvc4 初体验(一)

    [AllowAnonymous] [AllowAnonymous] 属性,允许匿名 在BaseControler里面加一个[Authorize],所有要验证的页面都继承BaseControler, 不 ...

  3. [原]git的使用(四)---撤销修改

    8.撤销修改 $ cat readme.txt Git is a distributed version control system. Git is free software distribute ...

  4. 部署OpenStack问题汇总(七)--解决apache启动错误"httpd:Could not reliably determine..."

    今天在调试openstack的时候,重启apache,出现以下报错: [root@hctrl log]# service httpd restart 停止 httpd:[确定] 正在启动 httpd: ...

  5. mysql优化之伪哈希索引

    想法非常简单,在标准的B-Tree索引上创建一个伪哈希索引.它和真正的哈希索引不是一回事,因为它还是使用B-Tree索引进行查找.然而,它将会使用键的哈希值进行查找,而不是键自身.你所要做的事情就是在 ...

  6. ssh命令远程登录

    1.查看SSH客户端版本 有的时候需要确认一下SSH客户端及其相应的版本号.使用ssh -V命令可以得到版本号.需要注意的是,Linux一般自带的是OpenSSH: 下面的例子即表明该系统正在使用Op ...

  7. mysql里查看时间

    MariaDB [jumpserver]> select current_time;+--------------+| current_time |+--------------+| 16:22 ...

  8. GDI+绘制半圆按钮

    新建一个用户控件: public partial class UserControl1 : UserControl { public UserControl1() { InitializeCompon ...

  9. 手写代码UI,xib和StoryBoard间的的优劣比较

    在UI制作方面,逐渐分化三种主要流派:使用代码手写UI:使用单个xib文件组织viewController或者view:使用StoryBoard来通过单个或很少的几个文件构建UI.三种方式各有优劣,也 ...

  10. python中filter(),map()和reduce()的用法及区别

    先看filter()方法 print(list(filter(lambda n : n % 2 == 1, range(20))))# 结果 [1, 3, 5, 7, 9, 11, 13, 15, 1 ...