zoukankan      html  css  js  c++  java
  • A1012. 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, 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 <stdio.h>
     2 #include <stdlib.h>
     3 #include <algorithm>
     4 #include <string.h>
     5 using namespace std;
     6 struct stu{
     7 int id;
     8 int grade[4];
     9 }s[2010];
    10 char course[4]={'A','C','M','E'};
    11 int rank1[1000000][4]={0};
    12 int now;
    13 bool cmp(stu a,stu b)
    14 {
    15 return a.grade[now]>b.grade[now];
    16 }
    17 
    18 int main(int argc, char* argv[])
    19 {
    20     int n,m;
    21 scanf("%d%d",&n,&m);
    22 for(int i=0;i<n;i++)
    23 {
    24 scanf("%d%d%d%d",&s[i].id,&s[i].grade[1],&s[i].grade[2],&s[i].grade[3]);
    25 s[i].grade[0]=(s[i].grade[1]+s[i].grade[2]+s[i].grade[3])/3;
    26 }
    27 for(now=0;now<4;now++)
    28 {
    29     sort(s,s+n,cmp);
    30     rank1[s[0].id][now]=1;
    31     for(int i=1;i<n;i++)
    32     {
    33     if(s[i].grade[now]==s[i-1].grade[now])
    34     {
    35     rank1[s[i].id][now]=rank1[s[i-1].id][now]; 
    36     }else
    37     {
    38      rank1[s[i].id][now]=i+1;
    39     }
    40     }
    41 }
    42 
    43 int query;
    44 for(int i=0;i<m;i++)
    45 {
    46     scanf("%d",&query);
    47     if(rank1[query][0]==0)
    48     {
    49     printf("N/A
    ");
    50     }else
    51 {
    52 int k=0;
    53 for(int j=0;j<4;j++)
    54 {
    55     if(rank1[query][j]<rank1[query][k])
    56     {
    57     k=j;
    58     }
    59 }
    60 printf("%d %c
    ",rank1[query][k],course[k]);
    61 }
    62 }
    63  
    64     system("pause"); 
    65     return 0;
    66 }
  • 相关阅读:
    在 Windows 10 中创建任何大小的虚拟测试文件的 2 种方法
    最近的github又不稳了。。ip host 大法来
    windows mklink /d /h /j 精讲
    kafka-manager配置和使用
    Java——七种垃圾收集器+JDK11最新ZGC
    聚簇索引和非聚簇索引(通俗易懂 言简意赅)
    【转载】Java中的锁机制 synchronized & 偏向锁 & 轻量级锁 & 重量级锁 & 各自优缺点及场景 & AtomicReference
    都1202年了奉劝那些还在用centos6的gs,赶紧切ubuntu-Centos6 升级 gcc 惨痛教训
    Tamper Chrome – 请求修改扩展,可用于Web安全测试
    线程、线程池三大方法、七大参数、四种策略
  • 原文地址:https://www.cnblogs.com/ligen/p/4337063.html
Copyright © 2011-2022 走看看