PAT 甲级1012. The Best Rank (25)
来源:互联网 发布:中国广电网络缴费 编辑:程序博客网 时间:2024/05/21 11:29
这道题的坑点在于需要注意输出的并列排名,比如90、60、60、50的对应排名应该是1、2、2、4,很容易搞成1、2、3、4千万注意这一点。
#include <iostream>#include <algorithm>#include <map>#include <vector>#include <string>using namespace std;struct student{ string StudentID; int score[4]; int bestRank; int currRank; char bestRankLable; student();};student::student(){ bestRank=2001;}char lables[]={'A','C','M','E'};int cmp0(const student A,const student B){ return A.score[0]>B.score[0];}int cmp1(const student A,const student B){ return A.score[1]>B.score[1];}int cmp2(const student A,const student B){ return A.score[2]>B.score[2];}int cmp3(const student A,const student B){ return A.score[3]>B.score[3];}vector <student> getBestRank(vector <student> &vS,int N,int lable){ vS[0].currRank=1; if(vS[0].bestRank>1){ vS[0].bestRank=1; vS[0].bestRankLable=lables[lable]; } for(int i=1;i<N;i++){ if(vS[i].score[lable]==vS[i-1].score[lable]){ vS[i].currRank=vS[i-1].currRank; }else{ vS[i].currRank=i+1; } if(vS[i].bestRank>vS[i].currRank){ vS[i].bestRank=vS[i].currRank; vS[i].bestRankLable=lables[lable]; } } return vS;}int main(int argc, char** argv) { int N,M; map<string,student> mStudent; vector<student> vStudent; student temp; string id; cin>>N>>M; for(int i=0;i<N;i++){ cin>>temp.StudentID>>temp.score[1]>>temp.score[2]>>temp.score[3]; temp.score[0]=(temp.score[1]+temp.score[2]+temp.score[3]); vStudent.push_back(temp); } sort(vStudent.begin(),vStudent.end(),cmp0); getBestRank(vStudent,N,0); sort(vStudent.begin(),vStudent.end(),cmp1); getBestRank(vStudent,N,1); sort(vStudent.begin(),vStudent.end(),cmp2); getBestRank(vStudent,N,2); sort(vStudent.begin(),vStudent.end(),cmp3); getBestRank(vStudent,N,3); for(int i=0;i<N;i++){ mStudent[vStudent[i].StudentID]=vStudent[i]; } for(int i=0;i<M;i++){ cin>>id; if(mStudent.count(id)>0){ cout<<mStudent[id].bestRank<<" "<<mStudent[id].bestRankLable<<endl; }else{ cout<<"N/A"<<endl; } }}
0 0
- 【PAT甲级】1012. The Best Rank (25)
- PAT甲级.1012. The Best Rank (25)
- 1012. The Best Rank (25) PAT甲级
- PAT甲级1012. The Best Rank (25)
- PAT 甲级1012. The Best Rank (25)
- PAT 甲级 1012. The Best Rank (25)
- PAT 甲级 1012. The Best Rank (25)
- PAT 甲级 1012. The Best Rank
- PAT甲级A1012. The Best Rank (25)
- 1012. The Best Rank (25)-PAT甲级真题
- PAT(甲级)1012. The Best Rank (25)
- PAT甲级练习1012. The Best Rank (25)
- PAT甲级真题1012. The Best Rank (25)
- [PAT甲级]1012. The Best Rank (25)(最好排名)
- PAT 1012(甲级) The Best Rank
- pat甲级1012-The Best Rank
- 1012. The Best Rank (25)-PAT
- pat 1012. The Best Rank (25)
- 数据压缩实验4-DPCM编码
- 安全开发相关注意事项
- QT涂鸦窗口/写字板
- BCL(基本类库)和FCL(框架类库)
- linux下安装MySQL
- PAT 甲级1012. The Best Rank (25)
- 字节流两个练习及乱码问题
- css 定位 position
- java写一个程序给保龄球比赛计分的程序
- 项目开发:SSH 之“department”模块从零开发
- 关于事务的一些基本
- poj 1328 贪心 转化
- 股市成交量
- ECMAScript6