PAT 1012
1012. The Best Rank (25)
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 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
题目不难,就是很烦。注意相同排名的处理。
代码
1 #include <stdio.h>
2 #include <string.h>
3 #include <algorithm>
4 using namespace std;
5
6 typedef struct Student{
7 char ID[];
8 double C,M,E,A;
9 }Student;
int search_rank(double *,double ,int);
int search_ID(Student *,char *,int );
int main()
{
double gradeC[],gradeM[],gradeE[],gradeA[];
Student student[];
int N,M,i;
while(scanf("%d%d",&N,&M) != EOF){
for(i=;i<N;++i){
scanf("%s%lf%lf%lf",student[i].ID,&student[i].C,&student[i].M,&student[i].E);
student[i].A = (student[i].C + student[i].M + student[i].E) / ;
gradeC[i] = student[i].C;
gradeM[i] = student[i].M;
gradeE[i] = student[i].E;
gradeA[i] = student[i].A;
}
sort(gradeC,gradeC+N);
sort(gradeM,gradeM+N);
sort(gradeE,gradeE+N);
sort(gradeA,gradeA+N);
char searchID[];
int rank,minRank;
char minRankOrder;
int ID_index;
for(i=;i<M;++i){
scanf("%s",searchID);
ID_index = search_ID(student,searchID,N);
if(ID_index < ){
printf("N/A\n");
continue;
}
minRank = search_rank(gradeA,student[ID_index].A,N);
minRankOrder = 'A';
if(minRank == ){
printf("1 A\n");
continue;
}
rank = search_rank(gradeC,student[ID_index].C,N);
if(rank < minRank){
minRank = rank;
minRankOrder = 'C';
}
if(minRank == ){
printf("1 C\n");
continue;
}
rank = search_rank(gradeM,student[ID_index].M,N);
if(rank < minRank){
minRank = rank;
minRankOrder = 'M';
}
if(minRank == ){
printf("1 M\n");
continue;
}
rank = search_rank(gradeE,student[ID_index].E,N);
if(rank < minRank){
minRank = rank;
minRankOrder = 'E';
}
printf("%d %c\n",minRank,minRankOrder);
}
}
return ;
}
int search_rank(double *data,double x,int n)
{
if(n <= )
return -;
int i = n-;
while(i >= && data[i--] != x);
if(data[++i] == x)
return n - i;
else
return -;
}
int search_ID(Student *data,char *ID,int n)
{
if(n <= )
return -;
int i=;
while(i < n && strcmp(data[i++].ID,ID));
if(!strcmp(data[--i].ID,ID))
return i;
else
return -;
}
PAT 1012的更多相关文章
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- PAT 1012 数字分类 (20)(代码+测试点)
1012 数字分类 (20)(20 分) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求 ...
- PAT——1012. 数字分类
给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...: ...
- PAT 1012. 数字分类 (20)
给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...: ...
- PAT 1012. The Best Rank
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- PAT 1012 数字分类
https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840 给定一系列正整数,请按要求对数字进行分类,并 ...
- PAT 1012 数字分类 C语言
给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...: ...
- PAT 1012 The Best Rank 排序
To evaluate the performance of our first year CS majored students, we consider their grades of three ...
- 【PAT】1012. The Best Rank (25)
题目链接: http://pat.zju.edu.cn/contests/pat-a-practise/1012 题目描述: To evaluate the performance of our fi ...
随机推荐
- 【转】iOS中16进制转10进制
原文网址:http://www.voidcn.com/blog/u012198553/article/p-4976772.html /// 将十六进制的字符串转化为NSData - (NSData ) ...
- jenkins+ant+ssh远程部署服务glassfish
jenkins安装可以参考官网或自己百度,这里不再说明: jenkins版本2.19.2 这里先说一下目的:主要是通过jenkins实现glassfish的部署,源码使用的是svn,编译是使用ant, ...
- LoadRunner常见问题整理(转)
首先要感谢群友的无私分享,才能得到这篇好的学习资料,整理得太好了,所以收藏保存,方便以后学习. 一:LoadRunner常见问题整理 1.LR 脚本为空的解决方法: 1.去掉ie设置中的第三方支持取消 ...
- xmbc 资源
http://raspberrypi.diandian.com/post/2013-02-25/40048470423 http://blog.csdn.net/lincyang/article/de ...
- C#打印100以内质数
bool b = false; ; i < ; i++) { ; j < i; j++) { ) { b = false; break; } else { b = true; } } if ...
- Notepad++中调用cl.exe编译器(Windows)
Notepad++中调用cl.exe编译器(Windows) 近来在notepad++中写代码,写完后总是习惯性的想去VS里面编译一下,看看代码是否有误.但有时候一些零碎的小文件总是懒得再VS中打开, ...
- SQL Server 用表中已有数据造数据
从表中选择数据再插入到表中(select XXX into 与insert into XXX select的结合) 在做性能测试时需要大量的业务数据.完全从画面造数据比较费时间,使用SQL文批量插入数 ...
- poj 1704 阶梯博弈
转自http://blog.sina.com.cn/s/blog_63e4cf2f0100tq4i.html 今天在POJ做了一道博弈题..进而了解到了阶梯博弈...下面阐述一下我对于阶梯博弈的理解. ...
- 【noip2005】篝火晚会
题解: 首先我们要知道一个性质: 把长度为n的序列变成目标序列最多需要n个操作 证明1: 我们可以将原序列上每位上的数字向目标序列相同位置的数字连一条有向边 如: 原序列: 1 2 3 目标序列: ...
- IntelliJ远程调试教程
概述 对于分布式系统的调试不知道大家有什么好的方法.对于我来说,在知道远程调试这个方法之前就是在代码中打各种log,然后重新部署,上线,调试,这样比较费时.今天咱们来了解了解Java远程调试这个牛逼的 ...