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. Scala的Option类型

    Scala的Option类型 为了让所有东西都是对象的目标更加一致,也为了遵循函数式编程的习惯,Scala鼓励你在变量和函数返回值可能不会引用任何值的时候使用Option类型.在没有值的时候,使用No ...

  2. java中抽象类与接口的区别

    1.abstract class 在 Java 语言中表示的是一种继承关系,一个类只能使用一次继承关系.但是,一个类却可以实现多个interface. 2.在abstract class 中可以有自己 ...

  3. 快速生成json实体类

    读取一个json文件,并与实体相对应: static void Main(string[] args) { string json = ""; FileStream fs = ne ...

  4. Toy Storage

    Toy Storage 题型与2318 TOYS一样,注意要对线段排序,现在模板又更新了~~ #include<iostream> #include<cstdio> #incl ...

  5. 13个小技巧帮你征服Xcode

    本文由CocoaChina翻译组成员唧唧歪歪(博客)翻译自David McGraw的博客原文:13 Xcode Tips That Will Help You Conquer Xcode当谈论到iOS ...

  6. to disable the entity lazy load, The ObjectContext instance has been disposed and can no longer be used for operations that require a connection.

    The ObjectContext instance has been disposed and can no longer be used for operations that require a ...

  7. iOS分类中通过runtime添加动态属性

    这个的话并不是说  可以  在程序运行的时候   来几个 未知的东西  就添加什么  1 2 3 4 5的属性.而是可以在系统原有类的基础上  给那个类 集合实际的工程来添加你方便实用的东西.比如   ...

  8. CSS标签居中

    CSS标签居中是相对于父标签说的,即在父标签的中居中.通常是在子标签中使用margin:0 auto,来使子标签居中.此外子标签需要有固定的宽度才行,比如 子标签为div时,div的宽度默认占父标签的 ...

  9. ORACLE 定时任务JOB

    http://www.cnblogs.com/xclw/archive/2009/12/04/1616945.html

  10. NGINX+UWSGI部署生产的DJANGO代码

    并且NGINX不用ROOT帐户哟. 1,编译安装NGINX及UWSGI及DJANGO,不表述 2,将NGINX文件夹更改为普通用户拥有.但执行文件NGINX仍为ROOT,运行如下命令加入特殊权限标志位 ...