1012 The Best Rank (25)(25 分)

1012 The Best Rank (25)(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  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

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

错了第三个数据,晚上再改中午突然想起来一个问题,会出现并列第一, 第 i 的情况没有处理此外 是否需要 四舍五入取 平均数? 测试提交了一下:发现不四舍五入(手动)也是可以的
//重复代码很多, 晚上修改一下
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std ; 

int n , m ;
#define maxn 3000

struct node{
    string ID ;
    int C,
        M,
        E,
        A;
    int rank_C,
        rank_M,
        rank_E,
        rank_A;
}; 

node peoper[maxn] ; 

bool cmp_C(node a , node b){
    return a.C > b.C ;
}

bool cmp_M(node a , node b){
    return a.M > b.M ;
}

bool cmp_E(node a , node b){
    return a.E > b.E ;
}

bool cmp_A(node a , node b){
    return a.A > b.A ;
}

char check_max_cat(int i, int max_rank){

    if(peoper[i].rank_A == max_rank){
        return ‘A‘ ;
    }else if(peoper[i].rank_C == max_rank){
        return ‘C‘ ;
    }else if(peoper[i].rank_M == max_rank){
        return ‘M‘ ;
    }else if(peoper[i].rank_E == max_rank){
        return ‘E‘ ;
    }

}

int check_rank(int i){
    int rank = min(peoper[i].rank_C, min(peoper[i].rank_M, min(peoper[i].rank_E, peoper[i].rank_A)));

    return rank ;
}

bool check(string ID , int &rank, char &category){
    for(int i=0 ; i<n ; i++){
        if(peoper[i].ID == ID){
            rank = check_rank(i) ;
            category = check_max_cat(i, rank) ;
            return true ;
        }
    }
    return false ;
}

int main(){

    while(cin >> n >> m ){
        // input
        for(int i=0 ; i<n ; i++){
            cin >> peoper[i].ID >> peoper[i].C >> peoper[i].M >> peoper[i].E  ;
            //peoper[i].A = (peoper[i].C + peoper[i].M + peoper[i].E)/3+0.5 ;
            peoper[i].A = (peoper[i].C + peoper[i].M + peoper[i].E) /3;

            peoper[i].rank_C = peoper[i].rank_M = peoper[i].rank_E = peoper[i].rank_A = 0 ;
        }

        sort(peoper , peoper+n , cmp_C) ; 

        for(int i=0 ; i<n ; i++){
            peoper[i].rank_C = i+1 ;
            // 可能出现 并列名次 的情况
            if(i>0 && peoper[i].C == peoper[i-1].C){
                peoper[i].rank_C = peoper[i-1].rank_C ;
            }
        }

        sort(peoper, peoper + n , cmp_M) ;
        for(int i=0 ; i<n ; i++){
            peoper[i].rank_M = i + 1 ;
            if(i>0 && peoper[i].M == peoper[i-1].M){
                peoper[i].rank_M = peoper[i-1].rank_M ;
            }
        }

        sort(peoper, peoper + n , cmp_E) ;
        for(int i=0 ; i<n ; i++){
            peoper[i].rank_E = i + 1 ;
            if(i>0 && peoper[i].E == peoper[i-1].E){
                peoper[i].rank_E = peoper[i-1].rank_E ;
            }
        }

        sort(peoper, peoper + n , cmp_A) ;
        for(int i=0 ; i<n ; i++){
            peoper[i].rank_A = i + 1 ;
            if(i>0 && peoper[i].A == peoper[i-1].A){
                peoper[i].rank_A = peoper[i-1].rank_A ;
            }
        }

        int rank ;
        char category ;
        string ID ; 

        for(int i=0 ; i<m ; i++){
            cin >> ID ;
            if(check(ID,rank, category)){
                cout << rank << " " << category << endl ;
            }else {
                cout << "N/A" << endl ;
            }
        }
    }

    return 0 ;
}    

原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9515741.html

时间: 2024-10-12 17:22:15

1012 The Best Rank (25)(25 分)的相关文章

[PTA] PAT(A) 1012 The Best Rank (25 分)

目录 Problem Solution Analysis Code Problem portal: 1012 The Best Rank (25 分) Solution Analysis ?一名学生有三门科目,以及计算出的一个平均成绩,每一个成绩都会有一个排名,现在想要让你输出某一个同学最高的排名(四种成绩排名的最高),以及对应的科目 ?如果给定的同学的四种课程排名的名次信息已经存在,那么就很简单,在里面找到最小的名次,以及对应的科目输出即可. ?可以创建四个数组,数组的每个元素存储某一门科目的

1012 The Best Rank (25分) vector与结构体排序

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

PAT 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 Algebra), and E - English. At the mean time, w

1012. The Best Rank (25)——PAT (Advanced Level) Practise

题目信息: 1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Math

1012. The Best Rank

1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To evaluate the performance of our first year CS majored students, we consider their grades of three courses only: C - C Programming Language, M - Mathematic

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 e

PAT Advanced 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 e

PAT:1012. The Best Rank (25) AC

#include<stdio.h> #include<algorithm> using namespace std; struct Student { int mID; int grade[4]; //0对应平均A,1对应C,2对应M,3对应E }STU[2010]; char course[4]={'A','C','M','E'}; //所有的存储都对应ACME int Rank[10000000][4]={0}; //每个学号四个成绩对应的排名 int now=0; //排序的

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 e