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
 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct{
int A;
int C;
int M;
int E;
char id[];
char best;
int bestRk, thisRk;
}student;
bool cmp1(student a, student b){
return a.A > b.A;
}
bool cmp2(student a, student b){
return a.C > b.C;
}
bool cmp3(student a, student b){
return a.M > b.M;
}
bool cmp4(student a, student b){
return a.E > b.E;
}
int main(){
int N, M, a, c, m ,e;
student info[];
char search[];
scanf("%d%d", &N, &M);
for(int i = ; i < N; i++){
scanf("%s%d%d%d", info[i].id, &info[i].C, &info[i].M, &info[i].E);
info[i].A = (info[i].C + info[i].E + info[i].M) / ;
}
sort(info, info + N, cmp4);
info[].bestRk = ;
info[].thisRk = ;
info[].best = 'E';
for(int i = ; i < N; i++){
if(info[i].E == info[i - ].E){
info[i].bestRk = info[i - ].bestRk;
info[i].thisRk = info[i - ].thisRk;
}else{
info[i].bestRk = i + ;
info[i].thisRk = i + ;
}
info[i].best = 'E';
}
sort(info, info + N, cmp3);
info[].thisRk = ;
if(info[].thisRk <= info[].bestRk){
info[].best = 'M';
info[].bestRk = ;
}
for(int i = ; i < N; i++){
if(info[i].M == info[i - ].M)
info[i].thisRk = info[i - ].thisRk;
else
info[i].thisRk = i + ;
if(info[i].thisRk <= info[i].bestRk){
info[i].best = 'M';
info[i].bestRk = info[i].thisRk;
}
}
sort(info, info + N, cmp2);
info[].thisRk = ;
if(info[].thisRk <= info[].bestRk){
info[].best = 'C';
info[].bestRk = ;
}
for(int i = ; i < N; i++){
if(info[i].C == info[i - ].C)
info[i].thisRk = info[i - ].thisRk;
else
info[i].thisRk = i + ;
if(info[i].thisRk <= info[i].bestRk){
info[i].best = 'C';
info[i].bestRk = info[i].thisRk;
}
} sort(info, info + N, cmp1);
info[].thisRk = ;
if(info[].thisRk <= info[].bestRk){
info[].best = 'A';
info[].bestRk = ;
}
for(int i = ; i < N; i++){
if(info[i].A == info[i - ].A)
info[i].thisRk = info[i - ].thisRk;
else
info[i].thisRk = i + ;
if(info[i].thisRk <= info[i].bestRk){
info[i].best = 'A';
info[i].bestRk = info[i].thisRk;
}
}
for(int i = ; i < M; i++){
scanf("%s", search);
int index = -;
for(int j = ; j < N; j++){
if(strcmp(info[j].id, search) == ){
index = j;
break;
}
}
if(index == -)
printf("N/A\n");
else
printf("%d %c\n", info[index].bestRk, info[index].best);
}
cin >> M;
return ;
}

总结:

1、排名依旧采用分数相同就名次相同,但需要占位的情况。对于题中要求的A、C、M、E的优先级,可以使优先级低的先比较。

最新文章

  1. OData的初步认识
  2. 深入理解ajax系列第一篇——XHR对象
  3. ubuntu ping响应慢的解决方法
  4. Oracle查询所有序列
  5. centos 谷歌浏览器安装
  6. 【转载】 Python动态生成变量
  7. 实验十四_访问CMOS RAM
  8. 高通平台msm8909 LK 实现LCD 兼容
  9. 【转】google谷歌百度收录网站的技巧方法,如何让百度收录?
  10. 如何在Mininet中修改host的IP地址
  11. Ehcache(2.9.x) - API Developer Guide, Basic Caching
  12. poj 2186 Popular Cows (强连通分量+缩点)
  13. Eclipes中使用BASE64Encoder及BASE64Decoder报错
  14. javascript 的点击复制事件
  15. 1.iOS第一个简单APP
  16. javascript call()函数
  17. java变量和数据类型总结
  18. Chartist.js-同时画柱状图和折线图
  19. 动态地添加HTML控件-JavaScript基础
  20. Qt 自定义按钮

热门文章

  1. Terraform:简介
  2. 个人作业Week2-代码复审(修改明确了要求)
  3. Linux实践:ELF文件格式分析
  4. 20135327郭皓--Linux内核分析第六周 进程的描述和进程的创建
  5. 我的Android之路——底部菜单栏的实现
  6. 使用代理创建连接池 proxyPool
  7. 【论文笔记】Domain Adaptation via Transfer Component Analysis
  8. 『编程题全队』&quot;Gugua&quot;事务管理系统项目宣传文案
  9. mybatis 框架网站
  10. shell脚本--显示文本内容