pat甲1012
1012 The Best Rank (25 分) https://pintia.cn/problem-sets/994805342720868352/problems/994805502658068480
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 Specification:
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 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
题目意思:
为了评估我们的计算机科学专业一年级学生的表现,我们只考虑他们的三门课程的成绩:C-C程序设计语言、M-数学(微积分或线性代数)和电子英语。同时,我们通过强调学生的最佳等级来鼓励学生——也就是说,在三门课程和平均成绩的四个等级中,我们为每个学生打印最佳等级。 例如,4名学生的C、M、E和A平均成绩如下:
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
由于第一名学生的C语言成绩最好,因此所有学生的最佳成绩排名都是第一名,而第二名学生的数学成绩最好,第三名学生的英语成绩最好,平均成绩是最后一名。 输入规格:
每个输入文件包含一个测试用例。每种情况从一行开始,其中包含两个数字N和M(≤2000),这两个数字分别是学生总数和将检查其等级的学生人数。接着是N行,每行包含一个学生ID,该ID是一个由6位数字组成的字符串,后跟该学生的三个整数等级(在[0,100]范围内),顺序为C、M和E。然后是M行,每行包含一个学生ID。
输出规格:
对于每个M学生,在一行中打印他/她的最佳等级,以及相应等级的符号,用空格隔开。
排序方法的优先级顺序为A>C>M>E。因此,如果有两种或两种以上的方法可以让学生获得相同的最佳排名,则输出优先级最高的方法。
如果学生不在评分表上,只需输出N/a即可。
样本输入:
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
样本输出:
1 C
1 M
1 E
1 A
3 A
N/A
具体代码如下:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct stu{
int id,best;
int score[4];
int rank[4];
};
int flag=-1,exist[1000000];
bool cmp(stu a,stu b){return a.score[flag]>b.score[flag];}
int main(){
int n,id,m;
scanf("%d %d",&n,&m);
vector<stu> v(n);
for(int i=0;i<n;i++){
cin>>v[i].id>>v[i].score[1]>>v[i].score[2]>>v[i].score[3];
v[i].score[0]=(v[i].score[1]+v[i].score[2]+v[i].score[3])/3;
}
for(flag=0;flag<4;flag++){
sort(v.begin(),v.end(),cmp);
v[0].rank[flag]=1;
for(int i=1;i<n;i++){
v[i].rank[flag]=i+1;
if(v[i].score[flag]==v[i-1].score[flag])v[i].rank[flag]=v[i-1].rank[flag];
}
}
for(int i=0;i<n;i++){
exist[v[i].id]=i+1;
v[i].best=0;
int minn=v[i].rank[0];
for(int j=1;j<=3;j++){
if(v[i].rank[j]<minn){
minn=v[i].rank[j];
v[i].best=j;
}
}
}
char c[5]={'A','C','M','E'};
for(int i=0;i<m;i++){
scanf("%d",&id);
int temp=exist[id];
if(temp){
int best=v[temp-1].best;
printf("%d %c\n",v[temp-1].rank[best],c[best]);
}else{
printf("N/A\n");
}
}
return 0;
}
浙公网安备 33010602011771号