PAT_A1012#The Best Rank

Source:

PAT A1012 The Best Rank (25 分)

Description:

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 CME 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 Specification:

Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤), 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 CMand E. Then there are M lines, each containing a student ID.

Output Specification:

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

Keys:

  • 模拟题

Attention:

  • 拿原数组排序去了,找错误找了半天,脑壳疼0,0

Code:

 1 /*
 2 Data: 2019-07-17 20:25:53
 3 Problem: PAT_A101#The Best Rank
 4 AC: 49:52
 5 
 6 题目大意:
 7 排名
 8 输入:
 9 第一行给出,学生总数N<=2e3,查询数M<=2e3
10 接下来N行,id,c,m,e
11 接下来M行,id
12 输出:
13 最好成绩,相应科目A>C>M>E
14 不存在N/A
15 */
16 
17 #include<cstdio>
18 #include<algorithm>
19 using namespace std;
20 const int M=1e4,H=1e7,N=4;
21 struct node
22 {
23     int id;
24     int grade[N],rnk[N];
25 }info[M];
26 int mp[H]={0},st[M],key;
27 char sub[N]={'A','C','M','E'};
28 
29 bool cmp(const int &a, const int &b)
30 {
31     return info[a].grade[key] > info[b].grade[key];
32 }
33 
34 int main()
35 {
36 #ifdef    ONLINE_JUDGE
37 #else
38     freopen("Test.txt", "r", stdin);
39 #endif
40 
41     int n,m,r,id;
42     scanf("%d%d", &n,&m);
43     for(int i=1; i<=n; i++)
44     {
45         scanf("%d",&info[i].id);
46         mp[info[i].id]=i;
47         st[i]=i;
48         for(int j=1; j<N; j++)
49             scanf("%d", &info[i].grade[j]);
50         info[i].grade[0]=info[i].grade[1]+info[i].grade[2]+info[i].grade[3];
51     }
52     for(int i=0; i<N; i++)
53     {
54         key=i;
55         sort(st+1,st+n+1,cmp);
56         for(int j=1; j<=n; j++)
57         {
58             int pre=st[j-1],now=st[j];
59             if(j==1 || info[pre].grade[i]!=info[now].grade[i])
60                 r=j;
61             info[now].rnk[i]=r;
62         }
63     }
64     for(int i=0; i<m; i++)
65     {
66         scanf("%d", &id);
67         if(mp[id]==0)
68         {
69             printf("N/A\n");
70             continue;
71         }
72         int best=0;
73         for(int j=1; j<N; j++)
74             if(info[mp[id]].rnk[j]<info[mp[id]].rnk[best])
75                 best=j;
76         printf("%d %c\n", info[mp[id]].rnk[best],sub[best]);
77     }
78 
79     return 0;
80 }

猜你喜欢

转载自www.cnblogs.com/blue-lin/p/11203767.html