PAT甲级1012
来源:互联网 发布:sql语句删除表中数据 编辑:程序博客网 时间:2024/05/23 12:32
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
#include<cstdio>#include<iostream>#include<string>#include<cstring>#include<map>#include<set>#include<vector>#include<algorithm>using namespace std;struct stu{string sn;int c, m, e,a;};int cmp(int a, int b){return a > b;}int main(){int N, M1;cin >> N >> M1;vector<int> C, M, E, A;string temp;vector<stu> v; stu s;while (N--){cin >> s.sn >>s.c >>s.m>> s.e;C.push_back(s.c);M.push_back(s.m);E.push_back(s.e);s.a = round((s.c + s.m + s.e) / 3);//可变为总分A.push_back(s.a);v.push_back(s);}bool flag;int rankC, rankM, rankE, rankA;int count = 0; multimap<int, char> mp;pair<int, char> p; vector<pair<int, int> > vpc,vpm,vpe,vpa; pair<int, int> pi;sort(C.begin(), C.end(),cmp);sort(M.begin(), M.end(),cmp);sort(E.begin(), E.end(),cmp);sort(A.begin(), A.end(),cmp);//int *rankA = new int[C.size()];if (C.size() > 0){int j = 1, k;pi.first = C[0];pi.second = j;k = j;vpc.push_back(pi);for (int i = 1; i < C.size(); i++){j++;if (C[i] == C[i - 1]){pi.first = C[i];pi.second = k;}else{pi.first = C[i];pi.second = j;k = j;}vpc.push_back(pi);}}if (E.size() > 0){int j = 1, k;pi.first = E[0];pi.second = j;k = j;vpe.push_back(pi);for (int i = 1; i < E.size(); i++){j++;if (E[i] == E[i - 1]){pi.first = E[i];pi.second = k;}else{pi.first = E[i];pi.second = j;k = j;}vpe.push_back(pi);}}if (A.size() > 0){int j = 1, k;pi.first = A[0];pi.second = j;k = j;vpa.push_back(pi);for (int i = 1; i < A.size(); i++){j++;if (A[i] == A[i - 1]){pi.first = A[i];pi.second = k;}else{pi.first = A[i];pi.second = j;k = j;}vpa.push_back(pi);}}if (M.size() > 0){int j = 1, k;pi.first = M[0];pi.second = j;k = j;vpm.push_back(pi);for (int i = 1; i < M.size(); i++){j++;if (M[i] == M[i - 1]){pi.first = M[i];pi.second = k;}else{pi.first = M[i];pi.second = j;k = j;}vpm.push_back(pi);}}while (M1--){cin >> temp;mp.clear();flag = false;for (int j = 0; j < v.size(); j++){if (v[j].sn == temp){flag = true;for (int k = 0; k < vpa.size(); k++){if (v[j].a == vpa[k].first){p.first= vpa[k].second;p.second = 'A';mp.insert(p);}}for (int k = 0; k < vpc.size(); k++){if (v[j].c == vpc[k].first){p.first = vpc[k].second;p.second = 'C';mp.insert(p);}}for (int k = 0; k < vpm.size(); k++){if (v[j].m == vpm[k].first){p.first = vpm[k].second;p.second = 'M';mp.insert(p);}}for (int k = 0; k < vpe.size(); k++){if (v[j].e == vpe[k].first){p.first = vpe[k].second;p.second = 'E';mp.insert(p);}}multimap<int, char>::iterator it = mp.begin();cout << it->first << " " << it->second << endl;}}if (!flag)cout << "N/A" << endl;}return 0;}/*这题做复杂了,不过先这样吧,以后重做一遍。那个排名不能是这样的:12334,而是12335,还有要想关键字相同,用multimap它的第二维不会继续比较,保持插入的顺序*/
- PAT(甲级)1012
- PAT甲级1012
- PAT甲级1012
- PAT甲级 1012
- 浙大PAT甲级-1012
- PAT 甲级
- 牛客网 PAT(甲级) 1012Kuchiguse (20)
- PAT 1012(甲级) The Best Rank
- pat甲级1012-The Best Rank
- PAT甲级 A1025.PAT RANKING
- PAT 甲级 1025 PAT Ranking
- PAT(甲级)1003
- PAT(甲级)1004
- PAT(甲级)1005
- PAT(甲级)1006
- PAT(甲级)1007
- PAT(甲级)1008
- PAT(甲级)1009
- 京东首页之页面分析
- iOS高级面试GCD初探
- SPOJ IITWPC4F - Gopu and the Grid Problem [线段树]【数据结构】
- 贪心+二分 (分蛋糕)HDU - 1969
- C#Attribute的使用
- PAT甲级1012
- java项目导出jar时图片等资源无法加载问题
- javascript入门之简单的交互
- Django(七)缓存、信号、Form
- Swap Nodes in Pairs
- dfs入门(2)
- 正则表达式符号字符大全
- 查找字符串中字母出现最多次数的方法小结
- ng2学习笔记(一)初识ng2