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. URL域名获取

    http://"是协议名 "www.test.com"是域名 "是端口号 "aaa"是站点名 "bbb.aspx"是页面 ...

  2. c++ 类内static成员初始化

    类内部的static成员,除了为const static 且为整数类型(int char bool)可在类内部初始化. 其他的都建议在对应的cpp文件中进行初始化. test.h #ifndef TE ...

  3. 浏览器缓存机制介绍 + 常用 http 状态码

    浏览器缓存分为两种, 强制缓存  与  协商缓存, https://www.pass4lead.com/300-209.htmlhttps://www.pass4lead.com/300-320.ht ...

  4. 解决Devexpress ChartControl的CalcHitInfo当中SeriesPoint为Null的问题

    Winform程序 ChartControl的RuntimeHitTesting属性一定要设为True. Line Series markers的Visible一定要弄成True.CalcHitInf ...

  5. svn版本管理

    代码发布方案: 1,安装,优化 软件环境,(nginx,lvs)  <-------运维工程师 2,程序代码(不断更新).   <--------开发工程师,(开发,运维都可以发布) 3, ...

  6. magent实现memcached集群的一个问题

    之前我们小组封装了一个memcached类库,里面有一个名为RemoveStartWith的方法可以根据起始字符串删除所有节点中负责键值规则的缓存项.它实现的原理就是通过stats命令获取每个节点的所 ...

  7. 使用Speech SDK 5.1文字转音频

    下载地址: http://www.microsoft.com/en-us/download/details.aspx?id=10121 SeppchSDK51.exe 语音合成引擎 SpeechSDK ...

  8. 【CF724F】Uniformly Branched Trees 动态规划

    [CF724F]Uniformly Branched Trees 题意:询问n个点的每个非叶子点度数恰好等于d的不同构的无根树的数目. $n\le 1000,d\le 10$. 题解:先考虑有根树的版 ...

  9. 使用COSBench工具对ceph s3接口进行压力测试

    一.COSBench安装 COSBench是Intel团队基于java开发,对云存储的测试工具,全称是Cloud object Storage Bench 吐槽下,貌似这套工具是intel上海团队开发 ...

  10. 爬虫之requests详解

    requests Python标准库中提供了:urllib.urllib2.httplib等模块以供Http请求,但是,它的 API 太渣了.它是为另一个时代.另一个互联网所创建的.它需要巨量的工作, ...