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的更多相关文章

  1. 浙大pat 1012题解

    1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...

  2. PAT 1012 数字分类 (20)(代码+测试点)

    1012 数字分类 (20)(20 分) 给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求 ...

  3. PAT——1012. 数字分类

    给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...: ...

  4. PAT 1012. 数字分类 (20)

    给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...: ...

  5. PAT 1012. The Best Rank

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

  6. PAT 1012 数字分类

    https://pintia.cn/problem-sets/994805260223102976/problems/994805311146147840 给定一系列正整数,请按要求对数字进行分类,并 ...

  7. PAT 1012 数字分类 C语言

    给定一系列正整数,请按要求对数字进行分类,并输出以下5个数字: A1 = 能被5整除的数字中所有偶数的和: A2 = 将被5除后余1的数字按给出顺序进行交错求和,即计算n1-n2+n3-n4...: ...

  8. PAT 1012 The Best Rank 排序

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

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

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

随机推荐

  1. apache开源项目--lume

    lume 是一个分布式.可靠和高可用的服务,用于收集.聚合以及移动大量日志数据,使用一个简单灵活的架构,就流数据模型.这是一个可靠.容错的服务.

  2. 【Java基础之容器】Iterator

    Iterator: ->所有实现了Collection接口的容器类都有一个iterator方法用以返回一个实现了Iterator接口的对象 ->Iterator对象称作迭代器,用以方便的实 ...

  3. SharePoint 2010 master page 控件介绍(3) :页面主体内容

    转:http://blog.csdn.net/lgm97/article/details/6409217 <!-- =====  页面滚动区域开始  ====================== ...

  4. c#中单元测试

    从走进.net后发现每天有写不完的代码,有做不完的测试...人感觉都已经机械,我们需要认清自己调整好心态,问下自己是否真的喜欢编程.我的答案当然也就是我爱编码,编码给我带来了许多欢乐,每天都给我体验小 ...

  5. 《深入Java虚拟机学习笔记》- 第11章 类型转换

    Java虚拟机包括许多进行基本类型转换工作的操作码,这些执行转换工作的操作码后面没有操作数,转换的值从栈顶断获得.Java虚拟机从栈顶端弹出一个值,对它进行转换,然后再把转换结果压入栈. int.lo ...

  6. FL2440移植u-boot2011.09

    u-boot version:2011.09-rc1 /home/lucas/u-boot-2011.09-rc1 OS:debian 7.1 cross-compilation chain:arm- ...

  7. bzoj 2656 [Zjoi2012]数列(sequence)(高精度)

    [题目链接] http://www.lydsy.com/JudgeOnline/problem.php?id=2656 [题意] 计算大数递推式 [思路] 高精度 [代码] #include<c ...

  8. 【转载】sed命令详解

    [转载自]http://www.cnblogs.com/edwardlost/archive/2010/09/17/1829145.html   sed -i  把后面的操作后的文本输出回原文本   ...

  9. python 错误处理

    在程序运行的过程中,如果发生了错误,可以事先约定返回一个错误代码,这样,就可以知道是否有错,以及出错的原因.在操作系统提供的调用中,返回错误码非常常见.比如打开文件的函数open(),成功时返回文件描 ...

  10. php 接收 Content-Type 是 application/json的请求数据

    工作中为其他公司编写了一个提供请求的接口,自己调试的时候是用form提交的,所以可以用$_POST取键接收方式,而对接联调的时候发现总是取不到数据,把$_POST整个序列化放入日志也是[] ,空的,于 ...