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 CME 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 Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤), 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 CM and E. Then there are M lines, each containing a student ID.

Output Specification:

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

题目分析:对数据进行处理就可 看了一下柳神的博客 更新相同排名不需要我这么麻烦
比如分数为 80 82 83 83 85
那么需要的排名应该为 1 2 3 3 5
经过处理得到未处理的排名为 1 2 3 4 5
if((*it).Score[i]==(*(it-1)).Score[i])
  (*it).Rank[i]=(*(it-1)).Rank[i];
这样可以了
 #include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int flag = ;
char Project[] = { 'C','M','E','A' };
typedef struct Score
{
int Student_Id;
int score[];
int Rank[];
int High;
int Pro;
}Scores;
bool compare(const Scores& a, const Scores& b)
{
return a.score[flag] > b.score[flag];
}
int main()
{
vector<Scores> S;
int N, M;
cin >> N >> M;
Scores t;
for (int i = ; i < N; i++)
{
cin >> t.Student_Id >> t.score[] >> t.score[] >> t.score[];
t.score[] = (t.score[] + t.score[] + t.score[]) / ;
S.push_back(t);
}
for (int i = ; i < ; i++)
{
sort(S.begin(), S.end(), compare);
(*S.begin()).Rank[flag] = ;
int j = ;
int truej = ;
for (vector<Scores>::iterator it = S.begin()+; it != S.end(); it++)
{
if ((*(it - )).score[flag] == (*it).score[flag])
{
(*it).Rank[flag] = j;
truej++;
}
else
{
(*it).Rank[flag] = truej;
j = truej++;
}
}
flag++;
}
for (vector<Scores>::iterator it = S.begin(); it != S.end(); it++)
{
int min = ;
int minp = ;
for (int i = ; i < ; i++)
{
if (min > (*it).Rank[i])
{
min = (*it).Rank[i];
minp = i;
}
}
if ((*it).Rank[] <=min)
{
min = (*it).Rank[];
minp = ;
}
(*it).High = min+;
(*it).Pro = minp;
}
for (int i = ; i < M; i++)
{
cin >> t.Student_Id;
int flag =;
for (vector<Scores>::iterator it = S.begin(); it != S.end(); it++)
if ((*it).Student_Id == t.Student_Id)
{
cout << (*it).High << " " << Project[(*it).Pro] << endl;
flag = ;
break;
}
if (!flag)
cout << "N/A"<<endl;
}
return ;
}

1012 The Best Rank (25 分)的更多相关文章

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

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

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

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

  3. 【PAT甲级】1012 The Best Rank (25 分)

    题意: 输入两个整数N,M(<=2000),接着分别输入N个学生的ID,C语言成绩,数学成绩和英语成绩. M次询问,每次输入学生ID,如果该ID不存在则输出N/A,存在则输出该学生排名最考前的一 ...

  4. 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 ...

  5. 【PAT】1012. The Best Rank (25)

    题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...

  6. 1012. The Best Rank (25)

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

  7. 1012 The Best Rank (25)(25 point(s))

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

  8. PAT-1012 The Best Rank (25 分) 查询分数对应排名(包括并列)

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

  9. PAT (Advanced Level) 1012. The Best Rank (25)

    简单排序题. 注意:分数相同的人排名相同. #include<iostream> #include<cstring> #include<cmath> #includ ...

随机推荐

  1. redis环境搭建及一主二从三哨兵模式配置

    一.单机redis环境搭建 1.安装: OS:linux redhat6.5 下载redis 官网下载链接:https://redis.io/download 把安装包上传到服务器,进行解压 [roo ...

  2. python虚拟环境安装使用

    # 安装 pip install virtualenv pip install virtualenvwrapper-win # win环境下 liunx下不需要-win #创建一个文件夹并cd进去mk ...

  3. SQL Server 存储过程 函数 和sql语句 区别

    存储过程与sql语句 存储过程的优点: 1.具有更好的性能   存储过程是预编译的,只在创建时进行编译,以后每次执行存储过程都不需再重新编译,   而一般 SQL 语句每执行一次就编译一次,因此使用存 ...

  4. ggplot2(3) 语法突破

    3.1 简介 图形图层语法基于Wilkinson的图形语法,并在其基础上添加了许多新功能,使得图形更有表现力,并能完美地嵌入到R的环境中. 图形图层语法使得图形的重复更新变得简单——每次只更新一个特征 ...

  5. 推荐一个学习python非常好的网站

    推荐一个入门python非常好的网站(也可以学习JAVA)非常适合入门,不说多易于理解,也是比较亲民的0基础学习教程,还免费…… 网址:https://www.liaoxuefeng.com/(廖雪峰 ...

  6. tesseract的简单使用

    Tesseract 是一个开源的 OCR 引擎,可以识别多种格式的图像文件并将其转换成文本,最初由 HP 公司开发,后来由 Google 维护.下载地址:https://digi.bib.uni-ma ...

  7. iview Checkbox 多选框 v-model 赋值方法 this.innerValueArr = [this.previousValue]

    iview Checkbox 多选框 v-model 赋值方法 this.innerValueArr = [this.previousValue]

  8. 【分布式锁】02-使用Redisson实现公平锁原理

    前言 前面分析了Redisson可重入锁的原理,主要是通过lua脚本加锁及设置过期时间来保证锁执行的原子性,然后每个线程获取锁会将获取锁的次数+1,释放锁会将当前锁次数-1,如果为0则表示释放锁成功. ...

  9. iOS 原生实现生成二维码(CoreImage)工具类,不依赖第三方库,可自定义背景颜色,添加logo(Swift 4.0)

    import Foundation import CoreImage import UIKit extension UIColor { var coreImageColor: CIColor { re ...

  10. ArrayList,HashSet,SortedSet之间的区别是什么?

    今天看Redis官方案例,出现了列表和集合概念,列表在Java中指的就是List,集合在Java中指的就是Set,那么怎么实现列表和集合,以及它们有什么区别呢? 我写了个Demo演示下: import ...