当前位置 : 主页 > 网络编程 > net编程 >

【PAT - 甲级1012】The Best Rank (25分)

来源:互联网 收集:自由互联 发布时间:2023-09-07
题干: 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​

题干:

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 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 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
999999

Sample 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 ;
}

 


上一篇:C# DBHelper和App.config的配置
下一篇:没有了
网友评论