1012. The Best Rank (25)

来源:互联网 发布:金立手机系统优化 编辑:程序博客网 时间:2024/06/04 20:09

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  A310101     98 85 88 90310102     70 95 88 84310103     82 87 94 88310104     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 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999
Sample Output
1 C1 M1 E1 A3 AN/A

这题感觉有猫腻。我在排序的时候>=就说我段错误。去掉=就过了

还有就是求平均值的时候,我看案例

310103     82 87 94 88
这个平均值是88,按照我的求法是87,我加上0.5,为的是四舍五入反而过的点更少
不管了。。

思路就是根据优先级,先后进行排序。
有个易错点,举个例子吧,假如几个人的平均成绩都是一样的,那么这个人的排名一定是1 A
但是你排序不一定会把这个人排到第一个。也有可能排到中间,所以中间要进行对这个人的成绩提前(相同成绩)
#include<iostream>#include<cstring>#include<cstdio>#include<queue>#include<stack>#include<set>#include<algorithm>#include<cmath>using namespace std;typedef struct node{    int name;int grade[4];}node;bool cmpA(node n1,node n2){return n1.grade[3]>n2.grade[3];}bool cmpC(node n1,node n2){return n1.grade[0]>n2.grade[0];}bool cmpM(node n1,node n2){return n1.grade[1]>n2.grade[1];}bool cmpE(node n1,node n2){return n1.grade[2]>n2.grade[2];}int main(){int n,m;cin>>n>>m;node n1[20100];set<int> s;for(int i=0;i<n;i++){cin>>n1[i].name>>n1[i].grade[0];cin>>n1[i].grade[1]>>n1[i].grade[2];n1[i].grade[3]=(n1[i].grade[0]+n1[i].grade[2]+n1[i].grade[1])/3.0;s.insert(n1[i].name);} for(int i=0;i<m;i++){int num;cin>>num;if(s.find(num)!=s.end()){int rank=0;char out;sort(n1,n1+n,cmpA);for(int i=0;i<n;i++){if(n1[i].name==num){int j=i;for( j=i;j>=0;j--){if(n1[i].grade[3]==n1[j].grade[3]) continue;else break;}rank=j+2;out='A';break;}}sort(n1,n1+n,cmpC);for(int i=0;i<n;i++){if(n1[i].name==num){int j=i;for( j=i;j>=0;j--){if(n1[i].grade[0]==n1[j].grade[0]) continue;else break;}if(j+2<rank){rank=j+2;out='C';}break;}}sort(n1,n1+n,cmpM);for(int i=0;i<n;i++){if(n1[i].name==num){    int j=i;for( j=i;j>=0;j--){if(n1[i].grade[1]==n1[j].grade[1]) continue;else break;}if(j+2<rank){rank=j+2;out='M';}break;}}sort(n1,n1+n,cmpE);for(int i=0;i<n;i++){if(n1[i].name==num){int j=i;for( j=i;j>=0;j--){if(n1[i].grade[2]==n1[j].grade[2]) continue;else break;}if(j+2<rank){rank=j+2;out='E';}break;}}cout<<rank<<" "<<out<<endl;}else{cout<<"N/A"<<endl;}}return 0;}




原创粉丝点击