【PAT - 甲级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 Algrbra), 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 A 310101 98 85 88 90 310102 70 95 88 84 310103 82 87 94 88 310104 91 91 91 91Then 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 Specification:
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 Specification:
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 Input:
5 6 310101 98 85 88 310102 70 95 88 310103 82 87 94 310104 91 91 91 310105 85 90 90 310101 310102 310103 310104 310105 999999Sample Output:
1 C 1 M 1 E 1 A 3 A N/A題目大意:
有n個學生,每個學生都有一個編號,和C,M,E三科的成績,和三科的平均平均成績A。為了鼓勵學生,每一次詢問給出一個學生編號,要求你輸出這個學生的最高排名的科目和對應的排名。
解題報告:?
因為這個題沒說對于平均分的舍入處理,所以這題保存成double或者四舍五入都可以AC。
注意對于排名,可能有并列的情況。
AC代碼:
#include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<stack> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define FF first #define SS second #define ll long long #define pb push_back #define pm make_pair using namespace std; typedef pair<int,int> PII; const int MAX = 2e4 + 5; struct Node {char name[12];int c,m,e,aa,cc,mm,ee;double a;int id; } R[MAX]; bool cmp1(Node a,Node b) {return a.a > b.a; } bool cmp2(Node a,Node b) {return a.c > b.c; } bool cmp3(Node a,Node b) {return a.m > b.m; } bool cmp4(Node a,Node b) {return a.e > b.e; } bool cmp(Node a,Node b) {return a.id < b.id; } char name[MAX]; map<string,PII> mp; char go(int x) {if(x == 1) return 'A';if(x == 2) return 'C';if(x == 3) return 'M';if(x == 4) return 'E'; } int main() {int n,m;cin>>n>>m;for(int i = 1; i<=n; i++) {scanf("%s%d%d%d",R[i].name,&R[i].c,&R[i].m,&R[i].e);R[i].a = (R[i].c + R[i].m + R[i].e) / 3.0; R[i].id = i;}sort(R+1,R+n+1,cmp1);int last = 0;for(int i = 1; i<=n; i++) {if(R[i].a == R[i-1].a) R[i].aa = last;else R[i].aa = i,last = i;}sort(R+1,R+n+1,cmp2); last = 0;for(int i = 1; i<=n; i++) {if(R[i].c == R[i-1].c) R[i].cc = last;else R[i].cc = i,last = i;}sort(R+1,R+n+1,cmp3); last = 0;for(int i = 1; i<=n; i++) {if(R[i].m == R[i-1].m) R[i].mm = last;else R[i].mm = i,last = i;}sort(R+1,R+n+1,cmp4); last = 0;for(int i = 1; i<=n; i++) {if(R[i].e == R[i-1].e) R[i].ee = last;else R[i].ee = i,last = i;}sort(R+1,R+n+1,cmp);for(int i = 1; i<=n; i++) {int item = 0,rk = 55555;if(R[i].aa < rk) item = 1,rk = R[i].aa;if(R[i].cc < rk) item = 2,rk = R[i].cc;if(R[i].mm < rk) item = 3,rk = R[i].mm;if(R[i].ee < rk) item = 4,rk = R[i].ee;mp[R[i].name] = pm(item,rk);}while(m--) {scanf("%s",name);if(mp.find(name) == mp.end()) printf("N/A\n");else printf("%d %c\n",mp[name].SS,go(mp[name].FF));}return 0 ; }?
總結
以上是生活随笔為你收集整理的【PAT - 甲级1012】The Best Rank (25分)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 办信用卡人员联系方式怎么获取 信用卡办理
- 下一篇: 这4个理财习惯,让你学会攒钱,离财务自由