1012. The Best Rank (25)

时间限制
400 ms
内存限制
32000 kB
代码长度限制
16000 B
判题程序
Standard
作者
CHEN, Yue

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

#include"iostream"
#include "algorithm"
#include <map>
#include <iomanip>
#include"string.h"
#include "vector"
using namespace std;

struct Student
{
int id;
int C;
int M;
int E;
int A;
};
bool compareA(Student a,Student b)
{
return a.A>b.A;
}
bool compareC(Student a,Student b)
{
return a.C>b.C;
}
bool compareM(Student a,Student b)
{
return a.M>b.M;
}
bool compareE(Student a,Student b)
{
return a.E>b.E;
}
int main()
{
vector<Student> stus;
map<int,char> Type;
map<int,int> Rank;
Student s;
int n,m;
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d%d%d%d",&s.id,&s.C,&s.M,&s.E);
s.A=(s.C+s.M+s.E)/3;
stus.push_back(s);
}
int score = -1;
int rank =0;
sort(stus.begin(),stus.end(),compareA);
for(int i=0;i<stus.size();i++)
{
if(stus[i].A!=score)
{
rank = i+1;
}
score = stus[i].A;
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'A';

}
score = -1;
rank =0;
sort(stus.begin(),stus.end(),compareC);
for(int i=0;i<stus.size();i++)
{
if(stus[i].C!=score)
{
rank = i+1;
}
score = stus[i].C;
if(Rank[stus[i].id]>rank)
{
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'C';
}
}
score = -1;
rank =0;
sort(stus.begin(),stus.end(),compareM);
for(int i=0;i<stus.size();i++)
{
if(stus[i].M!=score)
{
rank = i+1;
}
score = stus[i].M;
if(Rank[stus[i].id]>rank)
{
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'M';
}
}
score = -1;
rank =0;
sort(stus.begin(),stus.end(),compareE);
for(int i=0;i<stus.size();i++)
{
if(stus[i].E!=score)
{
rank = i+1;
}
score = stus[i].E;
if(Rank[stus[i].id]>rank)
{
Rank[stus[i].id] = rank;
Type[stus[i].id] = 'E';
}
}
int Q;
for(int i=0;i<m;i++)
{
cin>>Q;
if(Type.count(Q))
cout<<Rank[Q]<<" "<<Type[Q]<<endl;
else
cout<<"N/A"<<endl;
}

return 0;
}

浙大pat 1012题解的更多相关文章

  1. 浙大pat 1035题解

    1035. Password (20) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To prepare f ...

  2. 浙大pat 1025题解

    1025. PAT Ranking (25) 时间限制 200 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programmi ...

  3. 浙大pat 1011题解

    With the 2010 FIFA World Cup running, football fans the world over were becoming increasingly excite ...

  4. 浙大PAT 7-06 题解

    #include <stdio.h> #include <iostream> #include <algorithm> #include <math.h> ...

  5. 浙大 pat 1003 题解

    1003. Emergency (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue As an emerg ...

  6. 浙大 pat 1038 题解

    1038. Recover the Smallest Number (30) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHE ...

  7. 浙大 pat 1047题解

    1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...

  8. 浙大pat 1054 题解

    1054. The Dominant Color (20) 时间限制 100 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Behind the scen ...

  9. 浙大pat 1059 题解

    1059. Prime Factors (25) 时间限制 50 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 HE, Qinming Given ...

随机推荐

  1. cocos2d(CCSprite绑定不规则刚体与精灵一起移动)

    对于不规则的精灵我们可以借助PhysicsEditor来制作shape , 对于地图可以使用Tiled软件制作瓷砖地图. 今天主要记录一下如何把CCSprite与不规则刚体进行绑定,然后一起移动 // ...

  2. Ubuntu环境变量设置

    在配置Ubuntu里面的JDK环境变量时,从网上找到的资料各异,在不同的文件里面配置,如/etc/environment./etc/profile,环境变量设置都是可以的.但是难免会有其它的疑问,不同 ...

  3. javascript计算字符串中出现最多的字符和个数

    代码如下: <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <t ...

  4. C#操作Kentico cms

    C#操作Kentico cms 中的 content(winform环境) 前段时间做了个winform程序,去管理kentico网站的content,包括content节点的增删改查,以及相应节点内 ...

  5. mysql 建表 AUTO_INCREMENT , 数据类型 VARCHAR

    建表: 原帖地址: http://blog.sina.com.cn/s/blog_5da3d5c50100bjh0.html MySQL AUTO_INCREMENT 简介 (2009-01-02 1 ...

  6. Citrix 服务器虚拟化之三 Xenserver 网络管理

    Citrix 服务器虚拟化之三 Xenserver 网络管理 每个Xenserver服务器都有一个或多个网络.XenServer 网络是虚拟的以太网交换机,它可以连接到外部接口(带或不带 VLAN 标 ...

  7. C语言之三目运算符

    三目运算符 三目运算符:也叫三元运算符.这个运算符的符号是: ? : 语法: 表达式1 ? 表达式2 : 表达式3; 语义: 先执行表达式1,执行完毕,表达式1的结果如果为真,那么执行表达式2,并且这 ...

  8. EF 下的code fist 模式编程

    EF 分两种模式 codefirst(就是不知道数据是啥,也没有数据库)  和 database fist (数据已经设计好了) 首先打开vs  新建一个项目 创建一个控制台程序 然后 新建一个Tea ...

  9. unity 内置的CG结构解析

    一.Cg顶点程序必须在结构中传递顶点数据.几种常用的顶点结构定义在文件UnityCG.cginc中.在大部分情况下仅仅使用它们就够了.结构如下: 1.appdata_base: 包含顶点位置,法线和一 ...

  10. hdu1040

    #include<stdio.h>#include<stdlib.h>int a[100];int cmp(const void *a,const void *b){ retu ...