1012. The Best Rank (25)
来源:互联网 发布:pstn网络 编辑:程序博客网 时间:2024/05/18 03:51
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
#include <iostream>#include <cstring>using namespace std;struct Student{char ID[10];int score[4];int bestrank;char bestcourse;}stu[2000];char courses[]={'A' ,'C', 'M','E' };int main(){int n,m;cin>>n>>m;for(int i=0;i<n;i++){cin>>stu[i].ID>>stu[i].score[1]>>stu[i].score[2]>>stu[i].score[3];stu[i].score[0]=stu[i].score[1]+stu[i].score[2]+stu[i].score[3];}int j;for(int i=0;i<m;i++)//对每一个输入的ID进行计算?{char s[10];cin>>s;for(j=0;j<n;j++)//查看是否存在这个ID{if(0==strcmp(s,stu[j].ID)){int rank[4]={1,1,1,1};for(int k=0;k<n;k++)//计算这个ID的排名{if(stu[k].score[0]>stu[j].score[0])rank[0]++;if(stu[k].score[1]>stu[j].score[1])rank[1]++;if(stu[k].score[2]>stu[j].score[2])rank[2]++;if(stu[k].score[3]>stu[j].score[3])rank[3]++;}stu[j].bestrank=2000;for(int k=0;k<4;k++)if(rank[k]<stu[j].bestrank){stu[j].bestrank=rank[k];stu[j].bestcourse=courses[k];}cout<<stu[j].bestrank<< ' '<<stu[j].bestcourse<<endl;break;}}if(j==n)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)
- Swift中的!和?
- 1011. World Cup Betting (20)
- SQL Server不区分大小写的问题
- 图像处理+机器学习相关资源整合
- PHP关闭notice级别的错误提示
- 1012. The Best Rank (25)
- Handler消息传递机制(三)管理MessageQueue的Looper
- Android截屏方法
- 滚动条和滑动块
- iOS 开发,工程中混合使用 ARC 和非ARC
- 蓝桥杯 历届试题 兰顿蚂蚁
- 1013. Battle Over Cities (25)
- Canvas 图形
- pyqt文本框按回车触发事件