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. IOS开发之路三(XML解析之GDataXML的使用)

    最近再做一个项目需要用到xml的解析.今天查了一些资料自己做了一个小demo.纯OC没有界面.. 在IOS平台上进行XML文档的解析有很多种方法,在SDK里面有自带的解析方法,但是大多情况下都倾向于用 ...

  2. 【NET】Winform分页控件初探

    public partial class WinFormPager : UserControl { ; /// <summary> /// 当前页 /// </summary> ...

  3. 我的Pandas应用场景

    声明 工作后,很不幸的成为了团队中的QA.QA这个角色吧,说起来高大上,实际很苦逼,一句话概括一下:吃力不讨好!作为新人,公司每月一分钱没少我,至少现在跟开发的待遇是一样的,所以我还是得兢兢业业的对待 ...

  4. 总结C++中取成员函数地址的几种方法

    这里, 我整理了4种C++中取成员函数地址的方法, 第1,2,4种整理于网上的方法, 第3种cdecl_cast是我自己想到的. 其中, 第4种(汇编)的方法不能在VC6上编译通过. 推荐使用第1,2 ...

  5. 2013Esri全球用户大会之解读Web GIS

    1 什么是Web GIS,它跟我有什么关系? Web GIS是传递GIS功能的一种新方式,在Esri把GIS作为平台进行实现的战略方向中位于中心位置.Web GIS为用户随时随地访问和使用地理信息提供 ...

  6. Python自学笔记——Matplotlib风羽自定义

    [前言]对于气象专业的小学生来说,风场是预报重要的参考数据,我们所知的风羽有四种:短线代表风速2m/s,长线代表风速4m/s,空心三角代表风速20m/s,实心三角代表风速50m/s.而matplotl ...

  7. C语言之循环结构 for(一)

    一 for循环的介绍 语法: for(表达式1;表达式2;表达式3){ 循环体; } 循环步骤: A.执行表达式1,执行完毕跳转到B B.判断表达式2的结果是否为真,如果为真,跳转到C,否则跳转到E ...

  8. action = "#" 是什么意思 在HTML语言中

    action = "#" 是form标签的属性,代表提交数据到本页,如:// 提交数据到a.aspx页面<form action="a.aspx"> ...

  9. tab切换☆☆☆☆☆

    <!doctype html><html lang="en"><head> <meta charset="UTF-8" ...

  10. Spark集群搭建步骤

    问题: 参考:Spark快速入门指南 – Spark安装与基础使用