zoukankan      html  css  js  c++  java
  • 1012. The Best Rank

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

    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
      1 #include <iostream>
    2 #include <fstream>
    3 #include <vector>
    4 #include <string>
    5 #include <algorithm>
    6 #include <map>
    7 #include <stack>
    8 #include <cmath>
    9 #include <queue>
    10 #include <set>
    11 #include <list>
    12 #include <stdlib.h>
    13 #include <string.h>
    14
    15
    16 using namespace std;
    17
    18 class Student
    19 {
    20 public:
    21 string id;
    22 double M;
    23 double C;
    24 double E;
    25 double A;
    26 int rank_a;
    27 int rank_c;
    28 int rank_m;
    29 int rank_e;
    30 int best_rank;
    31 char best;
    32
    33 };
    34
    35 bool compA( const Student &stu1 , const Student &stu2 )
    36 {
    37 return stu1.A > stu2.A;
    38 }
    39
    40 bool compC( const Student &stu1 , const Student &stu2 )
    41 {
    42 return stu1.C > stu2.C;
    43 }
    44
    45 bool compM( const Student &stu1 , const Student &stu2 )
    46 {
    47 return stu1.M > stu2.M;
    48 }
    49
    50 bool compE( const Student &stu1 , const Student &stu2 )
    51 {
    52 return stu1.E > stu2.E;
    53 }
    54
    55
    56
    57 int main()
    58 {
    59
    60
    61 int N,M;
    62
    63 vector<Student> all;
    64
    65
    66 cin >> N >> M;
    67
    68 for( int i = 0 ; i < N ; ++i )
    69 {
    70 Student stu;
    71 cin >> stu.id;
    72 cin >> stu.C >> stu.M >> stu.E;
    73
    74 stu.A = (stu.C + stu.M + stu.E)/3;
    75 all.push_back(stu);
    76 }
    77
    78 sort( all.begin() , all.end() , compA );
    79
    80 for( int i = 0 ; i < all.size() ; ++i )
    81 {
    82 if( i == 0 )
    83 {
    84 all[i].rank_a = i+1;
    85 }
    86 else
    87 {
    88 if( all[i - 1].A == all[i].A )
    89 {
    90 all[i].rank_a = all[i-1].rank_a;
    91 }
    92 else
    93 {
    94 all[i].rank_a = i+1;
    95 }
    96 }
    97 }
    98
    99 sort( all.begin() , all.end() , compC );
    100
    101 for( int i = 0 ; i < all.size() ; ++i )
    102 {
    103 if( i == 0 )
    104 {
    105 all[i].rank_c = i+1;
    106 }
    107 else
    108 {
    109 if( all[i - 1].C == all[i].C )
    110 {
    111 all[i].rank_c = all[i-1].rank_c;
    112 }
    113 else
    114 {
    115 all[i].rank_c = i+1;
    116 }
    117 }
    118 }
    119
    120
    121 sort( all.begin() , all.end() , compM );
    122
    123 for( int i = 0 ; i < all.size() ; ++i )
    124 {
    125 if( i == 0 )
    126 {
    127 all[i].rank_m = i+1;
    128 }
    129 else
    130 {
    131 if( all[i - 1].M == all[i].M )
    132 {
    133 all[i].rank_m = all[i-1].rank_m;
    134 }
    135 else
    136 {
    137 all[i].rank_m = i+1;
    138 }
    139 }
    140 }
    141
    142 sort( all.begin() , all.end() , compE );
    143
    144 for( int i = 0 ; i < all.size() ; ++i )
    145 {
    146 if( i == 0 )
    147 {
    148 all[i].rank_e = i+1;
    149 }
    150 else
    151 {
    152 if( all[i - 1].E == all[i].E )
    153 {
    154 all[i].rank_e = all[i-1].rank_e;
    155 }
    156 else
    157 {
    158 all[i].rank_e = i+1;
    159 }
    160 }
    161 }
    162
    163 for( int i = 0 ; i < all.size() ; ++i )
    164 {
    165 int a = all[i].rank_a;
    166 int c = all[i].rank_c;
    167 int m = all[i].rank_m;
    168 int e = all[i].rank_e;
    169
    170 if( a <= c && a <=m && a <= e )
    171 {
    172 all[i].best_rank = a;
    173 all[i].best = 'A';
    174 }
    175 else if( c <= a && c <=m && c <= e )
    176 {
    177 all[i].best_rank = c;
    178 all[i].best = 'C';
    179 }
    180 else if( m <= a && m <=c && m <= e )
    181 {
    182 all[i].best_rank = m;
    183 all[i].best = 'M';
    184 }
    185 else
    186 {
    187 all[i].best_rank = e;
    188 all[i].best = 'E';
    189 }
    190 }
    191
    192 for( int i = 0 ; i < M ; ++i )
    193 {
    194 string id;
    195 cin >> id;
    196
    197 int p = 0;
    198 for( ; p< all.size() ; ++p )
    199 {
    200 if( all[p].id == id )
    201 {
    202 break;
    203 }
    204 }
    205
    206 if( p == all.size() )
    207 {
    208 cout << "N/A" << endl;
    209 }
    210 else
    211 {
    212 cout << all[p].best_rank << " " << all[p].best << endl;
    213 }
    214 }
    215
    216
    217 return 0;
    218 }


  • 相关阅读:
    Android 开发之 HelloWorld
    Spring 声明式事务管理
    对于初步搭建好的SSH框架进行简化(注解的使用)
    在已有的 eclipse 中离线配置 android 开发环境
    SSH框架整合总结
    Android的学习第六章(布局一TableLayout)
    Android的学习第六章(布局二--RelativeLayout)
    Android的学习第六章(布局一LinearLayout)
    我的Android第五章
    我的Android第四章
  • 原文地址:https://www.cnblogs.com/kking/p/2331802.html
Copyright © 2011-2022 走看看