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 ...
随机推荐
- ORACLE:profile的管理
PROFILE的管理(资源文件) 当需要设置资源限制时,必须设置数据库系统启动参数RESOURCE_LIMIT,此参数默认值为FALSE 可以使用如下命令来启动当前资源限制: ...
- CSS中的块级元素与行级元素
最近初学CSS时对块级元素与行级元素有时会产生混淆,写篇博客记录一下自己对其的理解. 先从概念上来看: 块级元素 特点:1.每个块级元素都是独自占一行,其后的元素也只能另起一行,并不能两个元素共用一行 ...
- 【转】vnc centos
原文:http://www.cnblogs.com/niocai/archive/2011/11/02/2233332.html 我的CentOS版本是6.0,下述方法在i386和x86_64中均适用 ...
- uvalive 3135 Argus priority_queue
用优先队列维护每个时间点优先级最高的元素. #include<iostream> #include<cstdio> #include<cstdlib> #inclu ...
- Spring MVC整合logback日志框架实战
1.引入依赖,本项目maven构建,普通项目导入想要的jar包即可 版本 <properties> <slf4j-api.version>1.7.7</slf4j-api ...
- HDU-4631 Sad Love Story 平面最近点对
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4631 数据是随机的,没有极端数据,所以可以分段考虑,最小值是一个单调不增的函数,然后每次分治算平面最近 ...
- HDU4862-Jump(最大流量最大费用流)
题意:有n*m的格子,每一个格子包含一个数字,0-9.你初始的能量为0,你可以玩k次,每一个你可以选择你现在的格子的正下方或者正右方的任意一个格子跳,但必须是之前没有跳过的格子.每玩一次你都可以跳任意 ...
- SQL2008-不同数据库之间的触发器
create trigger tr_update_Table_1 on rwqd FOR UPDATE As update dataabc.dbo.Table_1 set ...
- keil编译STM32工程时 #error directive: "Please select first the target STM32F10x device used in your application (in stm32f10x.h file)"
我们可以双击错误,然后会自动定位到文件 stm32f10x.h 中出错的地方,可以看到代码: #if !defined (STM32F10X_LD) && !defined (STM3 ...
- [iOS基础控件 - 4.2] APP列表 字典转模型Model
A.使用字典加载数据的缺点 1.用户自行指定key,容易出错 2.存入.取出都需要key,容易混乱 B.模型 (MVC中的model) 1.字典与模型对比: (1)字典:存储数据,通过字符串类型的 ...