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 91Then 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.输入整数N,M表示有N个学生的C/M/E成绩需要输入,有M个学生要查询他/她最好的平均/单课排名
2.输出这个学生最好的排名,以及是哪一科,中间用空格分割,若有相同最好排名,则输出优先级最大的输出(A>C>E>M)
思路:
1.首先要计算每个学生的平均成绩
2.计算每个学生每课的排名:先默认该学生该科成绩为第一,然后在成绩表中比较,遇到一个成绩比他好的,则排名+1
3.输出:默认该学生最好的排名科目为A,然后在去和C,M,E的排名比较,若发现排名更好的,则改变科目。
#include<iostream> #include<string> using namespace std; int main() { int N,M; int grade[3000][5]; int rank[3000][5]; int student[3000]; int average; cin>>N>>M; for(int i=0;i<N;i++) { average=0; for(int j=0;j<4;j++) { cin>>grade[i][j]; if(j!=0)average+=grade[i][j]; } grade[i][4]=average/3; } for(int i=0;i<M;i++) { cin>>student[i]; } /* cout<<"grades:\n"; for(int i=0;i<N;i++) { for(int j=0;j<5;j++) cout<<grade[i][j]<<" "; cout<<endl; }*/ // cout<<"rank:\n"; for(int i=0;i<N;i++) { rank[i][0]=grade[i][0]; // cout<<rank[i][0]<<" "; for(int j=1;j<5;j++) { rank[i][j]=1; for(int k=0;k<N;k++) { if(grade[i][j]<grade[k][j])rank[i][j]++; } //cout<<rank[i][j]<<" "; } //cout<<endl; } for(int i=0;i<M;i++) { int flag=-1; for(int j=0;j<N;j++) { if(student[i]==rank[j][0]) { flag=j; break; } } if(flag==-1) { cout<<"N/A\n"; continue; } int best=4; for(int k=1;k<4;k++) { if(rank[flag][best]>rank[flag][k])best=k; } if(best==1)cout<<rank[flag][best]<<" C\n"; else if(best==2)cout<<rank[flag][best]<<" M\n"; else if(best==3)cout<<rank[flag][best]<<" E\n"; else if(best==4)cout<<rank[flag][best]<<" A\n"; } return 0; }