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 tpl 模板页面如和给js文件传参数

    有一个参数,服务器传给了php 模板页面,但模板包含的js需要得到这个参数值.如何处理: 一,在引入页面前加一句代码 <script type="text/javascript&quo ...

  2. 分享自己动手弄的基于Rime的新世纪五笔输入法码表

    实验室新搞了一台iMac,没有支持新世纪的码表的中文输入法啊.搜索半天大家推荐用Rime(鼠须管)来挂接新世纪码表.不知道还有没有其它支持外挂码表的Mac版输入法,暂时只有搞这个了.看了一下别人已经做 ...

  3. 【javascript 引用类型(一)】

    javascript 的引用类型大致分为:Object 类型.Array 类型.Date 类型.RegExp 类型.Function 类型.基本包装类型和单体内置对象.这里我们着重介绍 Object ...

  4. 【python】元组的插入

    >>> temp=(1,2,3,4,5)>>> temp=temp[:2]+(8,)+temp[2:]>>> temp(1, 2, 8, 3, 4 ...

  5. 可以用来开发h5的软件小结

    webStorm phoneGap notepad++ eclips text sublime dreamWeaver intellij idea 学习h5 需要掌握的  大块的知识 xhtml ja ...

  6. Json字符串转换为java对象的各种实现方法【json_lib框架、Gson、org.json】

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://mengzhengbin520.blog.51cto.com/7590564/12 ...

  7. 实战 SSH 端口转发

    转自实战 SSH 端口转发 通过本文的介绍,读者可以从中了解到如何应用 SSH 端口转发机制来解决日常工作 / 生活中的一些问题.学会在非安全环境下使用端口转发来加密网络应用,保护个人隐私以及重要商业 ...

  8. Android sqlite 数据库在java代码中的增删改查

    private void queryPerson(PersonSQLiteOpenHelper personSQLiteOpenHelper) { SQLiteDatabase sqLiteDatab ...

  9. winRAR将单独文件分别压缩打包

    2014-4-7 首先选中多个需要打包的文件,右键-->添加到压缩文件-->选中"文件"选项卡-->勾选下面的"把每个文件压缩到单独文件中. 如下图所示

  10. v8 javascript engine

    https://code.google.com/p/v8-wiki/wiki/BuildingWithGYP vs2013git v8 http://github.com/v8/v8-git-mirr ...