【PAT Advanced Level】1012. The Best Rank (25)
来源:互联网 发布:全局近似算法 编辑:程序博客网 时间:2024/05/17 16:56
注意点:排名顺序如果有并列,则往后延续比如1 1 1 4 5而不是1 1 1 2 3
每次排序后更新每个学生的最好排名情况。
#include <iostream>#include <vector>#include <string>#include <algorithm>#include <fstream>using namespace std;struct Student{public:string id;int score[4];int bestRank;char subject;Student(string id, int c, int m, int e) : id(id) {score[0] = c;score[1] = m;score[2] = e;score[3] = (c + m + e) / 3;}};struct cmpA{bool operator()(const Student &s1, const Student &s2){return s1.score[3] > s2.score[3];}};struct cmpE{bool operator()(const Student &s1, const Student &s2){return s1.score[2] > s2.score[2];}};struct cmpM{bool operator()(const Student &s1, const Student &s2){return s1.score[1] > s2.score[1];}};struct cmpC{bool operator()(const Student &s1, const Student &s2){return s1.score[0] > s2.score[0];}};void updateRank(vector<Student> & v, const int subjectIndex){char s;if(subjectIndex == 0)s = 'C';else if(subjectIndex == 1)s = 'M';else if(subjectIndex == 2)s = 'E';else if(subjectIndex == 3)s = 'A';int rankb = 1;for(int i = 0; i < v.size(); i++){if(i == 0){if(rankb < v[i].bestRank){v[i].bestRank = rankb;v[i].subject = s;}}else{if(v[i].score[subjectIndex] != v[i - 1].score[subjectIndex])rankb = i + 1;if(rankb < v[i].bestRank){v[i].bestRank = rankb;v[i].subject = s;}}}}int main(){//fstream cin("a.txt");vector<Student> v;int p, q;cin>>p>>q;string id;int C;int M;int E;for(int i = 0; i < p; i++){cin>>id>>C>>M>>E;Student s(id, C, M, E);s.bestRank = p + 1;v.push_back(s);}sort(v.begin(), v.end(), cmpA());updateRank(v, 3);sort(v.begin(), v.end(), cmpC());updateRank(v, 0);sort(v.begin(), v.end(), cmpM());updateRank(v, 1);sort(v.begin(), v.end(), cmpE());updateRank(v, 2);for(int i = 0; i < q; i++){string s;cin>>s;int j;for(j = 0; j < v.size(); j++){if(v[j].id == s){cout<<v[j].bestRank<<" "<<v[j].subject<<endl;break;}}if(j != v.size())continue;cout<<"N/A"<<endl;}}
- 【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 (25)
- PAT (Advanced Level) Practise 1012. The Best Rank (25)
- PAT (Advanced) 1012. The Best Rank (25)
- PAT (Advanced) 1012. The Best Rank (25)
- 1012. The Best Rank @ PAT (Advanced Level) Practise
- [PAT (Advanced Level) ]1012. The Best Rank 解题文档
- 浙大 PAT Advanced level 1012. The Best Rank
- 浙大PAT (Advanced Level) Practise 1012 The Best Rank (25)
- PAT (Advanced Level) Practise 1012 The Best Rank (25)
- 1012. The Best Rank (25)——PAT (Advanced Level) Practise
- PAT (Advanced Level) 1012. The Best Rank (25) 最佳排名,结构体排序,哈希查询
- PAT(Advanced lecel) 1012. The Best Rank
- Pat(Advanced Level)Practice--1012(The Best Rank)
- PAT (Advanced Level) Practise 1012 The Best Rank
- PAT-PAT (Advanced Level) Practise 1012 The Best Rank (25) (简单模拟)【二星级】
- 最大流算法
- windows7下提示:“'telnet' 不是内部或外部命令 解决办法
- Alfresco 安装
- Oracle表的管理
- IP头结构详解
- 【PAT Advanced Level】1012. The Best Rank (25)
- 微信公众帐号开发系列教程第2篇-微信公众帐号的类型(普通和会议)
- 求等比数列之和
- 从源代码剖析Mahout推荐引擎
- 求利润数额
- 算法入门之DFS
- 第10周项目5-计算等比数列的和
- 第十周项目二——分数的累加(选做2)
- hive 报错 Caused by: java.lang.reflect.InvocationTargetException