当前位置: 首页 > article >正文

PAT A1012 The Best Rank

1012 The Best Rank

分数 25

作者 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 Specification:

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


 * 对n名同学按成绩平均数,C语言,数学,英语成绩优先级逐级递减,分别按成绩从高到低
 * 进行排列,成绩相同者排名相同,平均成绩按四舍五入处理;
 * 先用一个结构体存储学生的名字,各科成绩,后面分别按各优先级处理各科成绩,以及各科
 * 成绩的排名;
 *
 * 最后用一个unordered_map 来存储每个学生的姓名,以及他最好的科目的成绩排名和最好的科目
 * 的成绩排名下标;
 * 最后输入m个学生处理,输出即可。
 *
 * 具体操作参见代码

/**
 * 对n名同学按成绩平均数,C语言,数学,英语成绩优先级逐级递减,分别按成绩从高到低
 * 进行排列,成绩相同者排名相同,平均成绩按四舍五入处理;
 * 先用一个结构体存储学生的名字,各科成绩,后面分别按各优先级处理各科成绩,以及各科
 * 成绩的排名;
 * 
 * 最后用一个unordered_map 来存储每个学生的姓名,以及他最好的科目的成绩排名和最好的科目
 * 的成绩排名下标;
 * 最后输入m个学生处理,输出即可。
 * 
 * 具体操作参见代码
 */
 
#include <iostream>
#include <string>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef pair<int, int> PII;

struct Grade
{
    string name;
    int soc[4];
    int rank[4];
};

const int N = 1e4+10;
struct Grade stu[N];
unordered_map<string, PII> ump;

int n, m;

int flag = 0;

//用一个flag变量对四个成绩进行排名,后面用一个for循环处理,真的很高明啊;
//我最开始用了四个for循环,眼睛都看痛了,又学到一招
bool cmp(Grade a, Grade b)
{
    return a.soc[flag] > b.soc[flag];
}

int main()
{
    cin >> n >> m;
    for(int i=0; i<n; ++i)
    {
        int a[4];
        double db = 0;
        
        cin >> stu[i].name;
        for(int j=1; j<4; ++j)
        {
            cin >> stu[i].soc[j];
            db += stu[i].soc[j];
        }
        
        db /= 3;
        db += 0.5; //平均数四舍五入
        stu[i].soc[0] = db;  //soc[0]存储平均数
    }
    
    //对A,C,M,E 按成绩进行排序,从高到低排名,成绩相等并列排名
    for(flag = 0; flag < 4; ++flag)
    {
        sort(stu, stu + n, cmp);
        int cur = 1;
        for(int i=0; i<n; ++i)
        {
            if(i == 0 || stu[i].soc[flag] != stu[i-1].soc[flag])
                stu[i].rank[flag] = cur;
            else
                stu[i].rank[flag] = stu[i-1].rank[flag];
            ++cur;
        }
    }
    
    for(int i=0; i<n; ++i)
    {
        int maxv = N, idx = 0;
        
        for(int j=0; j<4; ++j)
        {
              if(stu[i].rank[j] < maxv)
              {
                  maxv = stu[i].rank[j];
                  idx = j;
              }
        }
        
        ump[stu[i].name] = {idx, maxv};
    }
    
    string str[] = {"A", "C", "M", "E"};
    
    while(m--)
    {
        string query;
        cin >> query;
        if(ump.find(query) == ump.end())
            puts("N/A");
        else
        {
            auto t = ump[query];
            cout << t.second << ' ' << str[t.first] << endl;
        }
    }
    
    return 0;
}


http://www.kler.cn/news/16815.html

相关文章:

  • iOS---iOS10适配iOS当前所有系统的远程推送
  • Ansible的基础了解
  • docker容器:本地私有仓库、harbor私有仓库部署与管理
  • 【Unity入门】24.碰撞检测
  • 滴水逆向三期笔记与作业——02C语言——02数据类型
  • JDBC详解(四):操作BLOB类型字段(超详解)
  • Python做个猫狗识别系统,给人美心善的邻居
  • matlab for循环详解
  • 其他自定义代码片段
  • 设计模式--装饰者模式
  • JSP+Struct+MySql基于BBS管理系统设计与实现(源代码+论文+中英资料+开题报告+答辩PPT)
  • Java 怎样实现代理模式,有什么优缺点
  • ospf扩展配置—认证、沉默接口、加快收敛、缺省路由
  • 2023-04-23 学习记录--C/C++-邂逅C/C++(中)
  • hive 清空分区表 多姿势对比
  • 微服务知识2
  • C语言文件操作【基础知识 + 顺序读写 + 文件版通讯录】
  • 【Java笔试强训 17】
  • maven install的时候报Unable to find main class
  • 财报解读:照明行业景气上行,欧普照明已步入增长“快车道”
  • Noah-MP陆面过程模型建模方法与站点、区域模拟实践技术
  • linux命令之tar详解
  • 快速了解车联网V2X通信
  • 接踵而至,昆仑万维天工大语言模型发布
  • Linux必会100个命令(六十)curl
  • 小满nestjs(第二十八章 nestjs 事务)
  • 1.软件测试
  • 常见元件、封装、尺寸、表面处理等
  • C语言中的三种语句
  • fastai2 实现SSD