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 Input5 6310101 98 85 88310102 70 95 88310103 82 87 94310104 91 91 91310105 85 90 90310101310102310103310104310105999999Sample Output
1 C1 M1 E1 A3 AN/A
还有就是求平均值的时候,我看案例
310103 82 87 94 88
#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;}
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 1012. The Best Rank (25)
- 欢迎使用CSDN-markdown编辑器
- 【Linux】crond机制以及cronttab命令
- 预习循环和循环以及作业
- MVC与单元测试实践之健身网站(七)-日程与打卡
- C++11中继承构造函数和委派构造函数
- 1012. The Best Rank (25)
- 包管理工具
- 如何让成为一个C/C++程序员
- 趣谈责任链模式
- Sabotage UVA
- CSS+JS实现简单的时钟
- 《Hadoop生态》——第二章 数据库与数据管理——MongoDB
- Vs2010发布Asp.Net网站及挂到IIS服务上
- GC总结