A1012. 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 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
 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <algorithm>
 4 #include <string.h>
 5 using namespace std;
 6 struct stu{
 7 int id;
 8 int grade[4];
 9 }s[2010];
10 char course[4]={‘A‘,‘C‘,‘M‘,‘E‘};
11 int rank1[1000000][4]={0};
12 int now;
13 bool cmp(stu a,stu b)
14 {
15 return a.grade[now]>b.grade[now];
16 }
17
18 int main(int argc, char* argv[])
19 {
20     int n,m;
21 scanf("%d%d",&n,&m);
22 for(int i=0;i<n;i++)
23 {
24 scanf("%d%d%d%d",&s[i].id,&s[i].grade[1],&s[i].grade[2],&s[i].grade[3]);
25 s[i].grade[0]=(s[i].grade[1]+s[i].grade[2]+s[i].grade[3])/3;
26 }
27 for(now=0;now<4;now++)
28 {
29     sort(s,s+n,cmp);
30     rank1[s[0].id][now]=1;
31     for(int i=1;i<n;i++)
32     {
33     if(s[i].grade[now]==s[i-1].grade[now])
34     {
35     rank1[s[i].id][now]=rank1[s[i-1].id][now];
36     }else
37     {
38      rank1[s[i].id][now]=i+1;
39     }
40     }
41 }
42
43 int query;
44 for(int i=0;i<m;i++)
45 {
46     scanf("%d",&query);
47     if(rank1[query][0]==0)
48     {
49     printf("N/A\n");
50     }else
51 {
52 int k=0;
53 for(int j=0;j<4;j++)
54 {
55     if(rank1[query][j]<rank1[query][k])
56     {
57     k=j;
58     }
59 }
60 printf("%d %c\n",rank1[query][k],course[k]);
61 }
62 }
63
64     system("pause");
65     return 0;
66 }
时间: 2024-11-14 22:19:38

A1012. The Best Rank (25)的相关文章

算法初步——排序 A1012.The Best Rank(25)

#include <bits/stdc++.h> #include<math.h> using namespace std; const int MAX_LEN = 2005; //const int MAX_D = 31; struct student{ int id; int Cgrade; int Mgrade; int Egrade; int Agrade; }stu[MAX_LEN]; int main(){ int n,m; scanf("%d%d"

PAT A1012 The Best Rank

PAT 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 Algrbra), and E - English. At the mean ti

pat1012. The Best Rank (25)

1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematic

PAT 1012. The Best Rank (25)

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 Algebra), and E - English. At the mean time, w

1012. The Best Rank (25)——PAT (Advanced Level) Practise

题目信息: 1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Math

1012 The Best Rank (25)(25 分)

1012 The Best Rank (25)(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 Algebra), and E - English. At the mean ti

[PTA] PAT(A) 1012 The Best Rank (25 分)

目录 Problem Solution Analysis Code Problem portal: 1012 The Best Rank (25 分) Solution Analysis ?一名学生有三门科目,以及计算出的一个平均成绩,每一个成绩都会有一个排名,现在想要让你输出某一个同学最高的排名(四种成绩排名的最高),以及对应的科目 ?如果给定的同学的四种课程排名的名次信息已经存在,那么就很简单,在里面找到最小的名次,以及对应的科目输出即可. ?可以创建四个数组,数组的每个元素存储某一门科目的

1012 The Best Rank (25分) vector与结构体排序

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, w

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 Algebra), and E - English. At the mean time, we encourage students by e