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 }
  • 相关阅读:
    Python的学习之旅———UDP
    Python的学习之旅———socket ,socketserver
    Python的学习之旅———time 模块
    python的学习之旅---面向对象
    Python的学习之旅———re 模块正则表达式
    有事没事找高宇哥聊天,李泽军爸妈聊天,管那么多人干嘛,活好自己
    还有教师观没有记
    Navicat中怎么查看数据库密码
    Oracle 删除用户时出现异常ora-01922: CASCADE must bu specified to drop 用户名
    kali使用sqlmap注入dvma
  • 原文地址:https://www.cnblogs.com/ligen/p/4337063.html
Copyright © 2011-2022 走看看