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 Algebra), 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<cstdio>
#include<iostream>
#include<algorithm>
#include<string.h>
using namespace std;
typedef struct{
int A;
int C;
int M;
int E;
char id[];
char best;
int bestRk, thisRk;
}student;
bool cmp1(student a, student b){
return a.A > b.A;
}
bool cmp2(student a, student b){
return a.C > b.C;
}
bool cmp3(student a, student b){
return a.M > b.M;
}
bool cmp4(student a, student b){
return a.E > b.E;
}
int main(){
int N, M, a, c, m ,e;
student info[];
char search[];
scanf("%d%d", &N, &M);
for(int i = ; i < N; i++){
scanf("%s%d%d%d", info[i].id, &info[i].C, &info[i].M, &info[i].E);
info[i].A = (info[i].C + info[i].E + info[i].M) / ;
}
sort(info, info + N, cmp4);
info[].bestRk = ;
info[].thisRk = ;
info[].best = 'E';
for(int i = ; i < N; i++){
if(info[i].E == info[i - ].E){
info[i].bestRk = info[i - ].bestRk;
info[i].thisRk = info[i - ].thisRk;
}else{
info[i].bestRk = i + ;
info[i].thisRk = i + ;
}
info[i].best = 'E';
}
sort(info, info + N, cmp3);
info[].thisRk = ;
if(info[].thisRk <= info[].bestRk){
info[].best = 'M';
info[].bestRk = ;
}
for(int i = ; i < N; i++){
if(info[i].M == info[i - ].M)
info[i].thisRk = info[i - ].thisRk;
else
info[i].thisRk = i + ;
if(info[i].thisRk <= info[i].bestRk){
info[i].best = 'M';
info[i].bestRk = info[i].thisRk;
}
}
sort(info, info + N, cmp2);
info[].thisRk = ;
if(info[].thisRk <= info[].bestRk){
info[].best = 'C';
info[].bestRk = ;
}
for(int i = ; i < N; i++){
if(info[i].C == info[i - ].C)
info[i].thisRk = info[i - ].thisRk;
else
info[i].thisRk = i + ;
if(info[i].thisRk <= info[i].bestRk){
info[i].best = 'C';
info[i].bestRk = info[i].thisRk;
}
} sort(info, info + N, cmp1);
info[].thisRk = ;
if(info[].thisRk <= info[].bestRk){
info[].best = 'A';
info[].bestRk = ;
}
for(int i = ; i < N; i++){
if(info[i].A == info[i - ].A)
info[i].thisRk = info[i - ].thisRk;
else
info[i].thisRk = i + ;
if(info[i].thisRk <= info[i].bestRk){
info[i].best = 'A';
info[i].bestRk = info[i].thisRk;
}
}
for(int i = ; i < M; i++){
scanf("%s", search);
int index = -;
for(int j = ; j < N; j++){
if(strcmp(info[j].id, search) == ){
index = j;
break;
}
}
if(index == -)
printf("N/A\n");
else
printf("%d %c\n", info[index].bestRk, info[index].best);
}
cin >> M;
return ;
}

总结:

1、排名依旧采用分数相同就名次相同,但需要占位的情况。对于题中要求的A、C、M、E的优先级,可以使优先级低的先比较。

A1012. The Best Rank的更多相关文章

  1. A1012 The Best Rank (25)(25 分)

    A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...

  2. PAT A1012 The Best Rank (25 分)——多次排序,排名

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  3. PAT甲级——A1012 The Best Rank

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  4. PTA A1011&A1012

    A1011 World Cup Betting (20 分) 题目内容 With the 2010 FIFA World Cup running, football fans the world ov ...

  5. PAT_A1012#The Best Rank

    Source: PAT A1012 The Best Rank (25 分) Description: To evaluate the performance of our first year CS ...

  6. 【算法学习记录-排序题】【PAT A1012】The Best Rank

    To evaluate the performance of our first year CS majored students, we consider their grades of three ...

  7. PAT A1012 Best Rank(25)

    题目描述 To evaluate the performance of our first year CS majored students, we consider their grades of ...

  8. 1012 The Best Rank (25 分)

    1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...

  9. UVA, 10336 Rank the Languages

    难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...

随机推荐

  1. 【下一代核心技术DevOps】:(二)Rancher的应用及优点简介

    1.环境选择 安装Rancher环境,一定要在干净的linux主机上进行,避免出现因配置导致的莫名其妙的问题.服务器操作系统建议CentOS7.4(内核3.10以上)低于这个版本的系统 如7.3 7. ...

  2. NTP服务部署和测试

    1. 概述2. 部署3. 配置4. 客户端配置4.1 客户端安装ntpdate4.2 同步设置 1. 概述 本篇博客主要记录如何部署一台NTP服务器,用于内网时间同步. 时间服务器对于集群内部节点之间 ...

  3. kvm虚拟化关闭虚拟网卡virbr0的方法

    我们知道:kvm虚拟化环境安装好后,ifconfig会发现多了一个虚拟网卡virbr0这是由于安装和启用了libvirt服务后生成的,libvirt在服务器(host)上生成一个 virtual ne ...

  4. 附加题(一)——interesting的抄袭现象

    这次的作业很有意思,是让我们搜索抄袭的同学的个人总结,并让我们列出链接,时间,作者及原因.其实我不是很能理解,抄袭现象是可耻的不受推崇的这是无可厚非,但是为什么要求我们大部分没有抄袭的同学去探究抄袭同 ...

  5. 初学习Qt的一些感悟

    最近用Qt写了个人项目,有如下心得(可能有不准确): Qt尽管没有扩展C++语法,但是有额外编译链,每个Q_OBJECT类编译的时候会用moc工具生成另一个meta C++类,之后就是标准C++编译流 ...

  6. sixsix团队“餐站”应用代码规范及开发文档

    网络爬虫文档 以下是我们软工小组关于网络爬虫部分代码的的说明文档.至于一些分功能的小函数或方法就不在此赘述,一看就能明白.下面就主要的函数进行说明. 从总体上来说主要有三部分:店家信息爬取部分,菜品信 ...

  7. 《Metasploit渗透测试魔鬼训练营》第一章读书笔记

    第1章 魔鬼训练营--初识Metasploit 20135301 1.1 什么是渗透测试 1.1.1 渗透测试的起源与定义 如果大家对军事感兴趣,会知道各国军队每年都会组织一些军事演习来锻炼军队的攻防 ...

  8. Linux内核期中

    Linux内核期中总结 一.计算机是如何工作的 个人理解:计算机就是通过和用户进行交互,执行用户的指令,这些指令存放在内存中,通过寄存器存储,堆栈变化,来一步步顺序执行. 二.存储程序计算机工作模型 ...

  9. LINUX内核分析第八周学习总结

    LINUX内核分析第八周学习总结 标签(空格分隔): 20135328陈都 陈都 原创作品转载请注明出处 <Linux内核分析>MOOC课程 http://mooc.study.163.c ...

  10. 基于SSH的高校网上选课系统的质量属性的实现

    我对于基于SSH的高校网上选课系统的质量属性的实现是从可用性.性能.安全性.可维护性.易用性五个方面进行的实现. 可用性方面: 实现方式:(1)当系统试图超出限制范围来进行课程查询或选课时必须进行错误 ...