标签:25 Student s2 s1 Rank student 91 id Best
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
1 #include<bits/stdc++.h> 2 using namespace std; 3 struct Student{ 4 int id,c,m,e; 5 float a; 6 }student[2005]; 7 bool CmpByA(Student s1,Student s2){ 8 return s1.a>s2.a; 9 } 10 bool CmpByC(Student s1,Student s2){ 11 return s1.c>s2.c; 12 } 13 bool CmpByM(Student s1,Student s2){ 14 return s1.m>s2.m; 15 } 16 bool CmpByE(Student s1,Student s2){ 17 return s1.e>s2.e; 18 } 19 20 int main(){ 21 int n,m,k; 22 vector<vector<int>> v(1000000); //存储排名信息,第一维是学号,第二维是学科排名,其中0、1、2、3分别表示a、c、m、e,如v[id][0]表示学号为id的同学的平均成绩排名 23 set<int> s; //单纯收集id用来判断该学号是否有效 24 cin>>n>>m; 25 for(int i=0;i<n;++i){ 26 cin>>student[i].id 27 >>student[i].c 28 >>student[i].m 29 >>student[i].e; 30 s.insert(student[i].id); 31 v[student[i].id].resize(5); 32 student[i].a=(student[i].c+student[i].m+student[i].e)/3; 33 } 34 sort(student,student+n,CmpByA); 35 v[student[0].id][0]=1; 36 for(int i=1;i<n;++i){ 37 if (student[i].a==student[i-1].a){ //判断是否并列,若和上一名同学并列则继承其排名 38 v[student[i].id][0]=v[student[i-1].id][0]; 39 } 40 else{ //不并列则按照正常排名来 41 v[student[i].id][0]=i+1; 42 } 43 } 44 sort(student,student+n,CmpByC); 45 v[student[0].id][1]=1; 46 for(int i=1;i<n;++i){ 47 if (student[i].c==student[i-1].c){ 48 v[student[i].id][1]=v[student[i-1].id][1]; 49 } 50 else{ 51 v[student[i].id][1]=i+1; 52 } 53 } 54 sort(student,student+n,CmpByM); 55 v[student[0].id][2]=1; 56 for(int i=1;i<n;++i){ 57 if (student[i].m==student[i-1].m){ 58 v[student[i].id][2]=v[student[i-1].id][2]; 59 } 60 else{ 61 v[student[i].id][2]=i+1; 62 } 63 } 64 sort(student,student+n,CmpByE); 65 v[student[0].id][3]=1; 66 for(int i=1;i<n;++i){ 67 if (student[i].e==student[i-1].e){ 68 v[student[i].id][3]=v[student[i-1].id][3]; 69 } 70 else{ 71 v[student[i].id][3]=i+1; 72 } 73 } 74 for (int i=0;i<m;i++){ 75 cin>>k; 76 if (s.find(k)!=s.end()){ 77 int index=0; 78 for(int j=1;j<4;++j){ 79 if (v[k][j]<v[k][index]){ 80 index=j; 81 } 82 } 83 switch(index){ 84 case 0:cout<<v[k][index]<<" A"<<endl;break; 85 case 1:cout<<v[k][index]<<" C"<<endl;break; 86 case 2:cout<<v[k][index]<<" M"<<endl;break; 87 case 3:cout<<v[k][index]<<" E"<<endl;break; 88 } 89 } 90 else{ 91 cout<<"N/A"<<endl; 92 } 93 } 94 }
tip:
1.这题我挂在2、3测试点,这两个测试点考察的是对于并列名次的处理,在生成排名时添加并列逻辑即可
2.申请二维vector时,需要声明第一维度的大小,且用v[i].resize(n)来开辟第二维的大小,否则会提示段错误,当然这题可以用其他更合理的数据结构来存储排名。
标签:25,Student,s2,s1,Rank,student,91,id,Best 来源: https://www.cnblogs.com/coderhrz/p/16631813.html
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。