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 ...
随机推荐
- 【数据库】Mysql中主键的几种表设计组合的实际应用效果
写在前面 前前后后忙忙碌碌,度过了新工作的三个月.博客许久未新,似乎对忙碌没有一点点防备.总结下来三个月不断的磨砺自己,努力从独乐乐转变到众乐乐,体会到不一样的是,连办公室的新玩意都能引起莫名的兴趣了 ...
- Mybatis 中 columnPrefix别名的用法
1.映射对应的属性,区分他们分别属于哪些类.(sql书写的时候为什么要将前缀加上(别名),是因为便于它去寻找哪个类的前缀是ANNEX_) 2.例: 如下所示当一个collection 定义了一个co ...
- CrackMe-005全破详解(图文+源码)--上篇
逆向破解 | 逆向 | 逆向分析 | CrackMe | Crack | CrackMe5 | CrackMe05 前言 CrackMe005,都说比较变态,很多人给放过去了,但是我还是决定上了它,既 ...
- 基于MongodbDB的用户认证-运维笔记
MongoDB默认是不认证的,默认没有账号,只要能连接上服务就可以对数据库进行各种操作,MongoDB认为安全最好的方法就是在一个可信的环境中运行它,保证之后可信的机器才能访问它,可能这些对一些要求高 ...
- 百度之星-day2-1004-二分答案
由于序列有序,求其中一个最优解,二分答案即可,注意二分时上边界满足才保存 #include<iostream> #include<stdio.h> #include<st ...
- ShowHand
实验目的: Github基本源代码控制方法 利用Junit4进行程序模块的测试,回归测试 编码规范的考量 C/Java等基本程序设计语言的运用. 实验过程: import java.util.Arra ...
- 第三个Sprint冲刺第八天(燃尽图)
- Windows 7 64位安装cURL
安装cURL. 1, 下载64位的SSL版cURL,网址: http://curl.download.nextag.com/download/curl-7.21.7-win64-ssl-sspi.zi ...
- Linux添加目录到环境变量以及添加sublime到环境变量
博主之前有过这种情况,就是在普通用户下su ls等命令还有效,可登陆进root用户之后这些常用的命令竟然失效了. 像这样 这问题其实很简单,但是对于不清楚环境变量的配置的同学来说也的确棘手,我之前就是 ...
- loadrunner分析结果二
5 worst transaction transaction name:事务名 failure ratio[%](exceeded time/transaction duration)失败率 (超标 ...