• PAT甲级——A1012 The Best Rank


    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 CME 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 (≤), 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 CM 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

    完了,英文不好会死人呀,看了别人的解释才知道,是找出每个学生在A,C,M,E中的最好排名
    如果在A、C、M、E排序过程中遇到同样的分数,需要有相同的排名,
    比如在A这一科上5个人的成绩分别是100,90,90,88,87的话,排名应该是1,2,2,4,5,
    这一点需要格外留意,不然没有办法通过所有测试。

     1 #include <iostream>
     2 #include <unordered_map>
     3 #include <string>
     4 #include <algorithm>
     5 #include <vector>
     6 #include <map>
     7 using namespace std;
     8 
     9 
    10 struct Data
    11 {
    12     string No;
    13     int num;
    14     int rank;
    15 };
    16 
    17 int main()
    18 {
    19     int N, M;
    20     cin >> N >> M;
    21     vector<Data>nums[4];//A C M E
    22     unordered_map <string, int>name;//用于学号查找
    23     for (int i = 0; i < N; ++i)
    24     {
    25         string No;
    26         int c, m, e;
    27         cin >> No >> c >> m >> e;
    28         name[No]++;
    29         nums[0].push_back({ No,(c + m + e) / 3,1 });
    30         nums[1].push_back({ No,c,1 });
    31         nums[2].push_back({ No,m,1 });
    32         nums[3].push_back({ No,e,1 });
    33     }
    34     for (int i = 0; i < 4; ++i)
    35     {
    36         sort(nums[i].begin(), nums[i].end(), [](Data d1, Data d2) {return d1.num > d2.num; });
    37         for (int j = 1; j < nums[i].size(); ++j)
    38         {
    39             if (nums[i][j].num == nums[i][j - 1].num)//处理相同分数
    40                 nums[i][j].rank = nums[i][j - 1].rank;
    41             else
    42                 nums[i][j].rank = j + 1;//要跳过相同排名
    43         }
    44     }
    45     
    46     for (int j = 0; j < M; ++j)
    47     {
    48         string No;
    49         cin >> No;
    50         int a, c, m, e;
    51         if (name[No] == 0)
    52             cout << "N/A" << endl;
    53         else
    54         {
    55             for (int i = 0; i < name.size(); ++i)
    56             {
    57                 if (nums[0][i].No == No)    a = nums[0][i].rank;
    58                 if (nums[1][i].No == No)    c = nums[1][i].rank;
    59                 if (nums[2][i].No == No)    m = nums[2][i].rank;
    60                 if (nums[3][i].No == No)    e = nums[3][i].rank;
    61             }            
    62             if (a <= c && a <= m && a <= e)                cout << a << " " << "A" << endl;
    63             else if (c <= a && c <= m && c <= e)        cout << c << " " << "C" << endl;
    64             else if (m <= a && m <= c && m <= e)        cout << m << " " << "M" << endl;
    65             else    cout << e << " " << "E" << endl;        
    66         }
    67     }
    68     return 0;
    69 }
  • 相关阅读:
    python_Opencv_使用Matplotlib模块
    django中同源策略和跨域解决方案
    ES6常用语法
    django之页面缓存
    django组件之ContentType
    我的博客园设置
    rest_framework 之版本控制
    rest_framework 之分页器
    在django项目中手动模拟实现settings的配置
    rest_framework之url控制器详解
  • 原文地址:https://www.cnblogs.com/zzw1024/p/11179407.html
Copyright © 2020-2023  润新知