A1012. The Best Rank
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的更多相关文章
- A1012 The Best Rank (25)(25 分)
A1012 The Best Rank (25)(25 分) To evaluate the performance of our first year CS majored students, we ...
- PAT A1012 The Best Rank (25 分)——多次排序,排名
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT甲级——A1012 The Best Rank
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PTA A1011&A1012
A1011 World Cup Betting (20 分) 题目内容 With the 2010 FIFA World Cup running, football fans the world ov ...
- PAT_A1012#The Best Rank
Source: PAT A1012 The Best Rank (25 分) Description: To evaluate the performance of our first year CS ...
- 【算法学习记录-排序题】【PAT A1012】The Best Rank
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT A1012 Best Rank(25)
题目描述 To evaluate the performance of our first year CS majored students, we consider their grades of ...
- 1012 The Best Rank (25 分)
1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...
- UVA, 10336 Rank the Languages
难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...
随机推荐
- Hexo博客搭建以及Next主题美化的经验之谈
这并不是一篇博客搭建教程.内容主要包含个人对于Hexo博客搭建的心得,Next6.0主题美化的部分建议,以及摘录一些各种用于博客搭建的link. 在博客园3年6个月,确实也学到了很多,博客园也是目前为 ...
- 仓储层接口IBaseRepository解析
//代码调用由业务层调用,调用方式详见源代码的业务层,升级直接替换TT模板即可,无需覆盖系统using System; using System.Collections.Generic; using ...
- 支持自定义协议的虚拟仪器【winform版】
首先,这个程序的由来,额,工作以来,做的最久的就是上位机,对市面上的大部分组态软件都感到不满,不好用,LabView虽然用起来不错,但是入门还是不够简单,刚好现在工作比较闲(已经不再做上位机了),所以 ...
- Redis主从复制原理总结
和Mysql主从复制的原因一样,Redis虽然读取写入的速度都特别快,但是也会产生读压力特别大的情况.为了分担读压力,Redis支持主从复制,Redis的主从结构可以采用一主多从或者级联结构,Redi ...
- Redis常用操作--------SortedSet(有序集合)
1.ZADD key score member [[score member] [score member] ...] 将一个或多个 member 元素及其 score 值加入到有序集 key 当中. ...
- poj3126 Prime Path(c语言)
Prime Path Description The ministers of the cabinet were quite upset by the message from the Chief ...
- 【Beta版本发布】爬虫队长装备全面更新!
一.Beta阶段目标回顾 1.为了解决Alpha阶段线程异常泛滥的问题,我们需要一个线程池. 2.为了爬取得到的文件正确可用,我们需要一个异常清理器. 3.为了不间断爬取,管理员不必频繁运行程序点,我 ...
- scipy的一些函数名
rvs:随机变量pdf:概率密度函数cdf:累计分布函数sf:残存函数(1-CDF)ppf:分位点函数(CDF的逆)isf:逆残存函数(sf的逆)stats:返回均值,方差,(费舍尔)偏态,(费舍尔) ...
- 正则表达式(java)
概念: 正则表达式,又称规则表达式.(英语:Regular Expression,在代码中常简写为regex.regexp或RE),计算机科学的一个概念. 正则表通常被用来检索.替换那些符合某个模式( ...
- ios开发之--CAKeyframeAnimation的详细用法
简单的创建一个带路径的动画效果,比较粗糙,不过事先原理都是一样的, 代码如下: 1,创建动画所需的view -(void)creatView { moveView = [UIView new]; mo ...