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. 剑指Offer:打印从1到最大的n位数

    题目:输入数值n,按顺序打印从1到最大的n位数,例如输入n=3,则从1,2,3,一直打印到999 陷阱:若使用循环遍历 1- 999...9 并依次输出,当位数n过大时,无论将其存入int或long或 ...

  2. [转] 三种Python下载url并保存文件的代码

    原文 三种Python下载url并保存文件的代码 利用程序自己编写下载文件挺有意思的. Python中最流行的方法就是通过Http利用urllib或者urllib2模块. 当然你也可以利用ftplib ...

  3. Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询

    1.搭建环境 新建JAVA项目,添加的包有: 有关Hadoop的hadoop-core-0.20.204.0.jar 有关Hbase的hbase-0.90.4.jar.hbase-0.90.4-tes ...

  4. 淘宝JAVA中间件Diamond详解(一)---简介&快速使用

    大家好,今天开始为大家带来我们通用产品团队的产品 —— diamond的专题,本次为大家介绍diamond的概况和快速使用. 一.概况 diamond是淘宝内部使用的一个管理持久配置的系统,它的特点是 ...

  5. [OFBiz]简介 一

    1.What is Apache OFBiz?http://ofbiz.apache.org/ 2.概述http://baike.baidu.com/view/638900.html?fromTagl ...

  6. uvalive 3263 That Nice Euler Circuit

    题意:平面上有一个包含n个端点的一笔画,第n个端点总是和第一个端点重合,因此团史一条闭合曲线.组成一笔画的线段可以相交,但是不会部分重叠.求这些线段将平面分成多少部分(包括封闭区域和无限大区域). 分 ...

  7. uvalive 4670 Dominating Patterns

    在文本串中找出现次数最多的子串. 思路:AC自动机模板+修改一下print函数. #include<stdio.h> #include<math.h> #include< ...

  8. HW6.21

    import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ...

  9. HDU-3487 Play with Chain Splay tee区间反转,移动

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3487 对于一个数列有两种操作:1.CUT a b c,先取出a-b区间的数,然后把它们放在取出后的第c ...

  10. Java程序员的10道XML面试题

    包括web开发人员的Java面试在内的各种面试中,XML面试题在各种编程工作的面试中很常见.XML是一种成熟的技术,经常作为从一个平台到其他平台传输数据的标准.XML面试问题包括用于转换XML文件的X ...