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:

  • Simulation title

Attention:

  • Take the original array to sort, to find the error to find a long, skull pain 0,0

Code:

. 1  / * 
2  the Data: 2019-07-17 20:25:53
 . 3  Problem: Best of The Rank # PAT_A101
 . 4  the AC: 49:52
 . 5  
. 6  subject to the effect:
 7  Rank
 8  Input:
 9  gives a first row, the total number of students N <= 2e3, the query number m <= 2E3
 10  Next N rows, ID, C, m, E
 . 11  next row m, ID
 12 is  output:
 13  bests, corresponding subject A> C> m> E
 14  does not exist N / A
 15  * / 
16  
. 17 #include <cstdio>
 18 is #include <algorithm>
 . 19  the using  namespace STD;
 20 is  const  int M = 1E4, 1E7 = H, 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 }

 

Guess you like

Origin www.cnblogs.com/blue-lin/p/11203767.html