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. c#基础系列2---深入理解 String

    "大菜":源于自己刚踏入猿途混沌时起,自我感觉不是一般的菜,因而得名"大菜",于自身共勉. 扩展阅读:深入理解值类型和引用类型 基本概念 string(严格来说 ...

  2. 以太坊remix-ide本地环境搭建

    remix-ide简介 ​ remix-ide是一款以太坊官方solisity语言的在线IDE,可用于智能合约的编写.测试与部署,不过某些时候可能是在离线环境下工作或者受限于网速原因,使用在线remi ...

  3. MariaDB 安装与启动 过程记录

    1. 安装之前的准备工作 rpm -qa |grep mysql rpm -qa |grep mariadb 按照查出来的软件包使用  yum remove  全部卸载,当然也可以 yum remov ...

  4. python基础学习笔记(三)

    序列概览 Python 包含6 种内建的序列,这里重点讨论最常用的两种类型:列表和元组. 列表与元组的主要区别在于,列表可以修改,元组则不能.也就是说如果要根据要求来添加元素,那么列表可以会更好用:而 ...

  5. 12.12 Daily Scrum

    这周末我们会集成一下反馈活跃用户的模块. 另外,今天编译的第一次测试结束,周末这两天项目的进度会比之前加快一些.   Today's Task Tomorrow's Task 丁辛 实现和菜谱相关的餐 ...

  6. beta阶段性能指标测试

    性能指标概况 安装耗时 启动耗时 CPU占用 内存占用 电池温度 网络流量 平均值 5.48s 1.04s 1.61% 18.68MB 32.44℃ 93.78B 峰值 131.74s 5.13s 5 ...

  7. Linux内核分析第四章读书笔记

    第四章 进程调度 进程调度程序:确保进程能有效工作的一个内核子程序 决定将哪个进程投入运行,何时运行已经运行多长时间 进程调度程序可看做在可运行态进程之间分配有限的处理器时间资源的内核子系统 原则:只 ...

  8. ShowHand

    实验目的: Github基本源代码控制方法 利用Junit4进行程序模块的测试,回归测试 编码规范的考量 C/Java等基本程序设计语言的运用. 实验过程: import java.util.Arra ...

  9. PAT 1016 部分A+B

    https://pintia.cn/problem-sets/994805260223102976/problems/994805306310115328 正整数A的“D~A~(为1位整数)部分”定义 ...

  10. Undertow的InMemorySessionManager

    https://github.com/undertow-io/undertow/blob/master/core/src/main/java/io/undertow/server/session/In ...