PAT (Advanced Level) Practice 1012 The Best Rank (25分)

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

这题是PAT甲级的1012题,题目描述为英文,题目的意思为:

1012的最好排名(25分)

为了评估我们第一年CS专业学生的表现,我们只考虑他们三门课程的成绩:C - C编程语言,M -数学(微积分或线性代数),和E -英语。同时,我们通过强调学生的最好等级来鼓励他们——也就是说,在三门课程和平均成绩的四个等级中,我们为每个学生打印出最好的等级。

例如,4名学生的C、M、E、A -的平均成绩如下:

学生ID C M E A
310101 98 85 88 90
310102 70 95 88 84
310103 82 87 94 88
310104 91 91 91 91

所有学生的最好成绩排名第一,因为第一名的C语言成绩最好,第二名的数学成绩最好,第三名的英语成绩最好,最后一名的平均成绩最好。

输入规格:

每个输入文件包含一个测试用例。每个案例都以一行开始,其中包含两个数字N和M(≤2000),这两个数字分别是学生总数和检查其排名的学生人数。然后是N行,每一行包含一个学生ID,它是一个6位数的字符串,后面是该学生的三个整数等级(范围为[0,100]),顺序为C、M和e。然后是M行,每一行包含一个学生ID。

输出规范:

对于每一位M名学生,打印出他/她的最佳排名,以及相应排名的符号,用空格隔开。

排序方法的优先级按 A>C>M>E排序。因此,如果一个学生有两种或两种以上的方法来获得相同的最佳排名,则输出优先级最高的方法。

如果一个学生不在评分名单上,简单地输出N/A。

示例输入:

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

输出示例:

1 C
1 M
1 E
1
3
N/A

#include<iostream>
#include <algorithm>
using namespace std;
int judge[1000005];
struct Rank{
    int id;
    int grade[4];
    int rank[4];
    int best;
}student[2005];
int i = -1;
string ss = "ACME";
bool cmp(Rank a,Rank b)
{
    return a.grade[i]>b.grade[i];
}
int main()
{
    int n,m;
    cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>student[i].id>>student[i].grade[1]>>student[i].grade[2]>>student[i].grade[3];
        student[i].grade[0]=int((student[i].grade[1]+student[i].grade[2]+student[i].grade[3])/3.0+0.5);
    }
    for(i = 0; i < 4; i++){//对学生进行排名,i控制每次排序的成绩
        sort(student,student+n,cmp);
        student[0].rank[i]=1;
        for(int j = 1; j < n; j++)
        {
            student[j].rank[i]=j+1;
            if(student[j].grade[i]==student[j-1].grade[i]) student[j].rank[i]=student[j-1].rank[i];
        }
    }
    for(int i = 0; i < n; i++){
        judge[student[i].id] = i + 1;
        int minv=student[i].rank[0];
        student[i].best=0;
        for(int j=1;j<=3;j++)
        {
            if(student[i].rank[j]<minv)
            {
                minv=student[i].rank[j];
                student[i].best=j;
            }
        }
    }
    for(int i=0;i<m;i++)
    {
        int id;
        cin>>id;
        if(judge[id]==0) cout<<"N/A"<<endl;
        else{
            int temp=judge[id]-1;
            int best = student[temp].best;
            printf("%d %c\n",student[temp].rank[best],ss[best]);
        }
    }
    return 0;
}
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

亓官劼

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值