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

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
// 1012pat1.cpp : 定义控制台应用程序的入口点。
//
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
using namespace std; const int INF=0x7fffffff;
struct Edge
{
string id;
int C,M,E,A;
}; struct R
{
int r;
char c;
bool flag;
R(){r=INF;c='A';flag=false;}
}; class TA:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.A>rhs.A;
}
};
class TC:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.C>rhs.C;
}
};
class TM:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.M>rhs.M;
}
};
class TE:public binary_function<Edge,Edge,bool>
{
public:
bool operator()(const Edge& lhs,const Edge& rhs) const
{
return lhs.E>rhs.E;
}
};
int main()
{
int n,m;
while(cinf>>n>>m)
{
Edge temp;
vector<Edge> vec;
map<string,R> rp;
for(int i=;i<=n;++i)
{
cinf>>temp.id>>temp.C>>temp.M>>temp.E;
rp[temp.id].flag=true;
temp.A=(temp.C+temp.M+temp.E)/;
vec.push_back(temp);
}
sort(vec.begin(),vec.end(),TA());
int rank=;
int cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->A==(iter+)->A)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='A';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='A';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='A';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='A';
}
}
}
sort(vec.begin(),vec.end(),TC());
rank=;
cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->C==(iter+)->C)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='C';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='C';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='C';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='C';
}
}
}
sort(vec.begin(),vec.end(),TM());
rank=;
cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->M==(iter+)->M)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='M';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='M';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='M';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='M';
}
}
}
sort(vec.begin(),vec.end(),TE());
rank=;
cnt=;
for(vector<Edge>::iterator iter=vec.begin();iter!=vec.end();++iter)
{
if((iter+)!=vec.end())
{
if(iter->E==(iter+)->E)
{
++cnt;
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='E';
}
if(rp[(iter+)->id].r>rank)
{
rp[(iter+)->id].r=rank;
rp[(iter+)->id].c='E';
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='E';
}
rank=rank+cnt;
cnt=;
}
}
else
{
if(rp[iter->id].r>rank)
{
rp[iter->id].r=rank;
rp[iter->id].c='E';
}
}
}
string id;
for(int i=;i<=m;++i)
{
cinf>>id;
if(rp[id].flag==true)
cout<<rp[id].r<<" "<<rp[id].c<<endl;
else
cout<<"N/A"<<endl;
}
}
return ;
}

PAT 1012. The Best Rank的更多相关文章

  1. PAT 1012 The Best Rank 排序

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  2. PAT甲级1012. The Best Rank

    PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...

  3. PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  4. PAT 1012

    1012. The Best Rank (25) To evaluate the performance of our first year CS majored students, we consi ...

  5. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  6. 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...

  7. 1012 The Best Rank

    1012 The Best Rank 1. 注意点 一名同学同样排名下的科目优先级问题 不同同学分数相同时排名相同,注意 排名不是 1 1 2 3 4 这种, 而是 1 1 3 4 5 注意到有些同学 ...

  8. 1012 The Best Rank (25分) vector与结构体排序

    1012 The Best Rank (25分)   To evaluate the performance of our first year CS majored students, we con ...

  9. 【PAT】1012. The Best Rank (25)

    题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...

随机推荐

  1. php练习7——类的运用(四则运算or面积计算[javascript小技巧——根据需求显示不同界面])

    要求:请编写一个类,该类可以进行四则运算,也可以进行矩形面积计算 1.程序 viewCount.html  Count.class.php      printCount.php 2.结果      ...

  2. HDU1004 (数组元素出现最多)

    HDU1004 思路:求数组中出现次数最多的那个元素: 遍历数组元素,找出每个元素出现的次数 Input Input contains multiple test cases. Each test c ...

  3. POJ 1961 Period KMP算法next数组的应用

    题目: http://poj.org/problem?id=1961 很好的题,但是不容易理解. 因为当kmp失配时,i = next[i],所以错位部分就是i - next[i],当s[0]...s ...

  4. 一篇文章让你彻底搞清楚Python中self的含义

    刚开始学习Python的类写法的时候觉得很是麻烦,为什么定义时需要而调用时又不需要,为什么不能内部简化从而减少我们敲击键盘的次数? 你看完这篇文章后就会明白所有的疑问. self代表类的实例,而非类. ...

  5. 记录一次配置unix网络编程环境的过程和遇到的问题

    记录一次搭建unix网络编程环境过程中遇到的问题和总结 计算机环境虚拟机 linuxmint-18-xfce-64bit 1.打开unix网络编程.iso 把目录下的文件复制到某一目录,修改权限,可命 ...

  6. bzoj 3160: 万径人踪灭 manachar + FFT

    3160: 万径人踪灭 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 133  Solved: 80[Submit][Status][Discuss] ...

  7. HDU 2487 Ugly window

    这是切的很痛苦的一道题,自己测试了很多样例却终究不过,中间也做了诸多修改,后来无奈去网上看题解,发现遗漏了一种情况,就是两个窗口可能边框都能看见,但是一个嵌套在另一里面,而我判定是不是 “top wi ...

  8. AsyncHttpClient 开源框架學習研究

    转载请注明出处:http://blog.csdn.net/krislight OverView: AsyncHttpClient庫 基於Apache的HttpClient框架,是一個異步的httpCl ...

  9. java.math.BigInteger使用心得总结(转)

    今天参考课本写了一个关于二进制与十进制转换的程序,程序算法不难,但写完后测试发现不论是二转十还是十转二,对于大于21亿即超过整数范围的数不能很好的转换.都会变成0.参考书籍发现使用使用BigInteg ...

  10. 【HDOJ】2157 How many ways??

    矩阵乘法,用DP做各种wa,后来发现原因了. #include <stdio.h> #include <string.h> typedef struct { ][]; } ma ...