[PAT (Advanced Level) ]1012. The Best Rank 解题文档
来源:互联网 发布:哪家的4g网络好 编辑:程序博客网 时间:2024/05/17 15:41
1012. The Best Rank (25)
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
此题涉及到排序算法,并且给出排名。需要考虑到的是,并列排名!!笔者实现的排序算法并不是最优化的算法。
C++代码如下。
#include<iostream>#include<string>#include<vector>using namespace std;int main(){ int N,M; cin>>N>>M; int rank[4][2000]={0}; vector<string> id; vector<int> grade[4]; id.resize(N); for(int i=0;i<4;i++) grade[i].resize(N); for(int i=0;i<N;i++){ int sum=0; cin>>id[i]; for(int j=1;j<4;j++){ cin>>grade[j][i]; sum+=grade[j][i]; } grade[0][i]=sum; } vector<string> queryId; queryId.resize(M); for(int i=0;i<M;i++){ cin>>queryId[i]; } //rank for(int i=0;i<4;i++){ int rankflag=0; for(int j=0;j<N;j++){ int bigj=0; int biggrade = 0; for(int k=0;k<N;k++){ if(rank[i][k]==0){ bigj=k; biggrade=grade[i][k]; } } for(int k=0;k<N;k++){ if(biggrade<grade[i][k]&&rank[i][k]==0){ biggrade=grade[i][k]; bigj=k; } } //we should consider the tied for ranking if(rank[i][bigj]==0) rank[i][bigj]=rankflag+1; int ttt=1; for(int k=0;k<N;k++){ if(biggrade==grade[i][k]&&rank[i][k]==0){ rank[i][k]=rankflag+1; ttt++; } } rankflag+=ttt; // cout<<rank[i][bigj]; } } //// for(int i=0;i<N;i++){// for(int j=0;j<4;j++)// cout<<rank[j][i]<<" ";// cout<<endl;// } for(int i=0;i<M;i++){ bool existflag=false; for(int j=0;j<N;j++){ if(queryId[i]==id[j]){ existflag=true; int bestrank=N+1; int bestflag=0; for(int k=0;k<4;k++){ if(bestrank>rank[k][j]){ bestrank=rank[k][j]; bestflag=k; } } cout<<bestrank<<" "; switch(bestflag){ case 0: {cout<<"A"; break; }case 1: { cout<<"C"; break; }case 2: { cout<<"M"; break; }case 3: { cout<<"E"; break; } } cout<<endl; break; } } if(!existflag) cout<<"N/A"<<endl; } return 0;}
测试点全部通过。
- [PAT (Advanced Level) ]1012. The Best Rank 解题文档
- 1012. The Best Rank @ PAT (Advanced Level) Practise
- 【PAT Advanced Level】1012. The Best Rank (25)
- 【c++】PAT (Advanced Level)1012. The Best Rank (25)*
- PAT (Advanced Level) Practise 1012. The Best Rank (25)
- 浙大 PAT Advanced level 1012. The Best Rank
- 【PAT】【Advanced Level】1012. The Best Rank (25)
- PAT (Advanced Level) Practise 1012. The Best Rank (25)
- PAT (Advanced) 1012. The Best Rank (25)
- PAT(Advanced lecel) 1012. The Best Rank
- PAT (Advanced) 1012. The Best Rank (25)
- 浙大PAT (Advanced Level) Practise 1012 The Best Rank (25)
- Pat(Advanced Level)Practice--1012(The Best Rank)
- PAT (Advanced Level) Practise 1012 The Best Rank (25)
- PAT (Advanced Level) Practise 1012 The Best Rank
- 1012. The Best Rank (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) 1012. The Best Rank (25) 最佳排名,结构体排序,哈希查询
- PAT-PAT (Advanced Level) Practise 1012 The Best Rank (25) (简单模拟)【二星级】
- Java 多进程的生产和消费实现
- 47. PHP 魔术方法
- 点击"确定"按钮,屏幕颜色随机变化,并显示对应的RBG值
- android 利用正则表达式 控制edittext只能输入数字、英文、汉字
- Handler--异步消息处理机制
- [PAT (Advanced Level) ]1012. The Best Rank 解题文档
- virtualbox 中Linux 如何使用多个IP地址
- PowerDesigner生成Excel版本的数据库文件
- Apache2+Tomcat7负载均衡配置
- 20151017计算出租车打车费用
- jQuery源码分析之jQuery.event.fix方法五问
- 51nod 1136 欧拉函数
- Linux 浏览器下安装 Flash
- 《项目管理艺术》第五、六章读书摘要-想法从何而来、有了想法该如何去做