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:
Student ID 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

题目意思:已知n个学生的3门科目的分数,平均分可以通过3门成绩计算得到,这样就会有4种排名C(C Programming Language)、M(Mathematics)、E(English)、A(Average),对于K次查询,给一个学生的ID,输出该学生在4种排名中最好的排名和排名方式,如果在多种排名方式中的排名相同,那么按照A>C>M>E的顺序输出,如果ID不存在

输出N/A。

解题思路:这个题已经有点成绩查询系统的意思了,核心是排序,需要注意的一点是排名并列应该是1、1、3、4、5而不是1、1、2、3、4。

#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
struct student{
int id;
int best;
int score[];
int ranks[];
}stu[];
int vis[];
int flag;
int cmp(student A,student B)
{
return A.score[flag]>B.score[flag];
} int main()
{
int n,m,id,i,j,best,temp;
char c[]={'A','C','M','E'};
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
scanf("%d%d%d%d",&stu[i].id,&stu[i].score[],&stu[i].score[],&stu[i].score[]);
stu[i].score[]=(stu[i].score[]+stu[i].score[]+stu[i].score[])/3.0;//平均分
}
for(flag=;flag<=;flag++)//确定排名,保存在不同flag下的排名
{
sort(stu,stu+n,cmp);
stu[].ranks[flag]=;
for(i=;i<n;i++)
{
stu[i].ranks[flag]=i+;
if(stu[i].score[flag]==stu[i-].score[flag])//成绩相同。排名将会并列
{
stu[i].ranks[flag]=stu[i-].ranks[flag];
}
}
}
for(i=;i<n;i++)//确定每个人在4种排名方式下的最好排名
{
vis[stu[i].id]=i+;//序号
stu[i].best=;
int mins=stu[i].ranks[];
for(j=;j<=;j++)
{
if(stu[i].ranks[j]<mins)
{
mins=stu[i].ranks[j];
stu[i].best=j;
}
}
}
for(i=;i<m;i++)
{
scanf("%d",&id);
temp=vis[id];
if(temp)
{
best=stu[temp-].best;
printf("%d %c\n", stu[temp-].ranks[best], c[best]);
}
else
{
printf("N/A\n");
}
}
return ;
}

PAT 1012 The Best Rank 排序的更多相关文章

  1. PAT 1012. The Best Rank

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

  2. PAT甲级1012. The Best Rank

    PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...

  3. PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  4. 1012 The Best Rank (25分) vector与结构体排序

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

  5. 1012 The Best Rank (25 分)

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

  6. PAT 1012

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

  7. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  8. 1012 The Best Rank

    1012 The Best Rank 1. 注意点 一名同学同样排名下的科目优先级问题 不同同学分数相同时排名相同,注意 排名不是 1 1 2 3 4 这种, 而是 1 1 3 4 5 注意到有些同学 ...

  9. PAT 甲级 1012 The Best Rank (25 分)(结构体排序)

    题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...

随机推荐

  1. AQS系列(三)- ReentrantReadWriteLock读写锁的加锁

    前言 前两篇我们讲述了ReentrantLock的加锁释放锁过程,相对而言比较简单,本篇进入深水区,看看ReentrantReadWriteLock-读写锁的加锁过程是如何实现的,继续拜读老Lea凌厉 ...

  2. cmake常用命令总结

    最近研究了下cmake,总结了一些常用命令,方便以后快速查找. project(projectname [CXX] [C] [Java]): 设置工程名. set(VAR [VALUE] [CACHE ...

  3. Python、 Pycharm、Django安装详细教程(图文)

    前言 这篇文章主要介绍了Python. Pycharm.Django安装详细教程,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧. ...

  4. PHP7.3安装event扩展

    安装支持库libevent wget https://github.com/libevent/libevent/releases/download/release-2.1.11-stable/libe ...

  5. JS---DOM/BOM---学习road map---7 parts

    JS---DOM/BOM---学习road map---6 parts Part 1-2: Part 3-4 part 5-7:

  6. 如何减小ABAP业务代码的复杂度

    在程序开发的过程中,相同的功能往往有不同的实现方式.对于可以实现同样功能的不同代码,复杂度是用于比较其质量优劣的重要指标. 在本文中,代码复杂度是指代码被理解/修改的难易程度.越容易被理解.修改的代码 ...

  7. Win10系统重做

    一.准备工作: 1.电脑(台式电脑.笔记本电脑): 2.U盘(内存大于4G): 3.软碟通(UltraISO):下载地址:https://pan.baidu.com/s/1tpCiIyIwK_7LaL ...

  8. deepin镜像 mxlinux镜像 ubuntu镜像桌面版

    百度网盘https://pan.baidu.com/s/18HX4XgXRMXFho036tuP-Hw

  9. C# 多线程总结 异常处理 线程取消 锁(lock)

    那么什么时候能用多线程? 任务能并发的时候 多线程能干嘛?提升速度/优化用户体验 网站首页:A数据库 B接口 C分布式服务 D搜索引擎,适合多线程并发,都完成后才能返回给用户,需要等待WaitAll列 ...

  10. Python——面向对象(类)的基础疑难点

    相信用Python写def函数大家都信手拈来了,但Python作为面向对象的编程语言,怎么能浪费呢? 那问题来了.什么是类呢?什么是实例?什么是对象?方法是什么??属性又是什么???继承?封装?多态? ...