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. Struts2更改配置文件struts.xml默认路径

    struts2配置文件默认存放路径在/WEB-INF/classes目录下,即将struts.xml放在src的目录下. 但是为了协作开发与方便管理,我们有时需要把struts.xml放到其他位置 s ...

  2. EasyUI实现异步加载tree(整合Struts2)

    首先jsp页面有一ul用于展现Tree <ul id="mytree"></ul> 加载Tree <script type="text/ja ...

  3. WPF实现打印功能

    WPF实现打印功能 在WPF 中可以通过PrintDialog 类方便的实现应用程序打印功能,本文将使用一个简单实例进行演示.首先在VS中编辑一个图形(如下图所示). 将需要打印的内容放入同一个< ...

  4. longlistselector 闪烁问题研究

    在使用微博的时候,发现微博列表偶尔闪一下.后来自己在写应用的时候也出现了这个问题,不过微博用的是listbox,而我用的是longlistselector.仔细关注了一下,发现闪烁的内容是最后一个it ...

  5. 解决WP7的32位图像渐变色色阶问题

    做游戏时发现背景图色阶现象严重,想了想会不会是显卡色深问题,于是加了下面一段代码,结果解决这个问题. graphics.PreferredBackBufferFormat = Microsoft.Xn ...

  6. Windows下的环境搭建Erlang

    Windows下的环境搭建 Erlang 一.安装编译器 在http://www.erlang.org/download.html下载R16B01 Windows Binary File并安装. 二. ...

  7. 大数据应用日志采集之Scribe 安装配置指南

    大数据应用日志采集之Scribe 安装配置指南 大数据应用日志采集之Scribe 安装配置指南 1.概述 Scribe是Facebook开源的日志收集系统,在Facebook内部已经得到大量的应用.它 ...

  8. Hibernate的clear(),flush(),evict()方法详解

    1.Clear 方法 无论是Load 还是 Get 都会首先查找缓存(一级缓存) 如果没有,才会去数据库查找,调用Clear() 方法,可以强制清除Session缓存. 例: 这里虽然用了2个get方 ...

  9. 编程利用利用curses库编程开始

    时间紧张,先记一笔,后续优化与完善. curses库常用函数: 注意编译时要用这样的格式:gcc xxx.c -l curses -o xxx 第一个小例子: include <stdio.h& ...

  10. 解决 jQuery.UI.Resizable aspectRatio在init后无法重新设置

    一.背景  在jQuery1.9.x版本之前,存在aspectRatio在Resizable方法init之后,无法再次修改aspectRatio的boolean值. 二.解决方案 // 用于fix j ...