[PAT甲级]1012. The Best Rank (25)(最好排名)

PAT甲级 1012 The Best Rank CMECMEandA。 阅读详情

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

题目大意:

  • 给出n个学生的id, C M E的课程成绩,然后给出m个学生的id,输出他们的最好排名和排名的依据(即ACME)
  • 每个学生有四个成绩 C M E和A,A是C M E的平均成绩,每个学生可以有四个排名,若是出现其中两个或者多个排名一样的,优先级为 A > C > M > E

思路:

  • 每个学生有四个排名,先定义一个结构体,存储学生的id,成绩,排名和最好排名
  • 随后输入过程中计算平均成绩A
  • 按照各科成绩进行排名,分别记录
  • 统计每个学生最好排名, 同时用exist数组保存当前id是否存在,这个id对应的结构体的下标是多少。用i+1可以保证为0的都是不存在的可以直接输出N/A,其余不为0的保存的值是对应的结构体index + 1的值
  • 思路参考,点击链接

代码:

#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
using namespace std;
struct node{
    int id,best;
    int score[4],rank[4];//分数  排名
}stu[2001];
int exist[1000000];//用于检查d是否存在
int flag = -1;
int cmd(node a, node b){return a.score[flag] > b.score[flag];}
int main()
{
    int n,m;
    cin >> n >> m;//n行学生成绩 m个要输出的人数
    for(int i=0; i<n; i++){
        scanf("%d %d %d %d", &stu[i].id, &stu[i].score[1], &stu[i].score[2], &stu[i].score[3]);
        stu[i].score[0] = (stu[i].score[1]+stu[i].score[2]+stu[i].score[3]+1.5)/3;//四舍五入
    }
    for(flag=0; flag<=3; flag++){//分别记录各科排名
        sort(stu, stu+n, cmd);
        stu[0].rank[flag] = 1;
        for(int i=1; i<n; i++){
            stu[i].rank[flag] = i+1;
            if(stu[i].score[flag] == stu[i-1].score[flag])//排名并列应该1、1、3、4、5,而不是1、1、2、3、4
                stu[i].rank[flag] = stu[i-1].rank[flag];
        }
    }
    for(int i=0; i<n; i++){
        exist[stu[i].id] = i+1;//记录学生目前的排名(最后一次排序)
        stu[i].best = 0;//找出学生四种排名中最好的
        int t = stu[i].rank[0];
        for(int j=1; j<=3; j++){
            if(stu[i].rank[j] < t){
                t = stu[i].rank[j];
                stu[i].best = j;
            }
        }
    }
    char c[] = {'A', 'C', 'M', 'E'};
    for(int i=0; i<m; i++){
        int id;
        scanf("%d", &id);
        int temp = exist[id];
        if(temp != 0){
            int best = stu[temp-1].best;
            printf("%d %c\n", stu[temp-1].rank[best], c[best]);
        }else{
            printf("N/A\n");//id不存在
        }
    }
    return 0;
}
2021.9.11 PAT顶级(100分) T1 开局刚看的时候没怎么看懂题,写了个假算法样例没过。开完T2回过头来重新读的题。 大致题意: 给出一组(key,value)对,按key值升序排列,以此为建堆顺序,根据value值建立小根堆,对建好的堆层序遍历。 做法: 读完题不太想去建堆(主要是太久没写代码,调试起来比较麻烦),找了个别的做法,对一个序列[l,r]遍历一遍找到value值最小的位置pos,记录pos,再把序列拆分成[l,pos-1]和[pos+1,r]两段重复如上做法,按层存储pos,遍历一遍输出。 难度大致 div2.B #incl 阅读详情

相关推荐

浙江大学pat题目集合(1001-1091)

浙江大学的程序能力测试(pat)上所有advanced级别的题目集合的更新版本,从1001到最新的1091全部都有。纯手工制作,花了不少时间调整了格式以方便阅读,欢迎大家下载,平时放在pad或者手机上可以回顾回顾,思考思考。 当时我就是用它充实我闲余时间,作用显著,喜欢的童鞋不要错过!

四大含金量高的算法证书考试

四大含金量高的算法证书考试

QYgujingjing的专栏 1万+

Shopee商品详情页反爬实战:手把手逆向x-sap-Ri和x-sap-Sec请求头加密

本文详细解析了Shopee商品详情页反爬机制中x-sap-Ri和x-sap-Sec请求头参数的加密逻辑,通过JS逆向技术手把手教你定位加密入口、分析哈希算法与对称加密实现,并提供完整实战案例和应对反爬策略的高级技巧,助力开发者突破电商平台数据采集难点。

weixin_27875131的博客 1830

PAT学习资料汇总(PAT甲级、PAT顶级、PAT考试经验)

二、PAT甲级 PAT甲级真题目录(按题型整理) PAT甲级真题目录(按题型整理)_love music.的博客-优快云博客_pat甲级真题 PAT甲【所有题目+解析+代码示例+总结】附带所有历年整体+讲解+代码 PAT甲【所有题目+解析+代码示例+总结】附带所有历年整体+讲解+代码_繁星蓝雨的博客-优快云博客 2020年9月PAT甲级满分必备刷题技巧 2020年9月PAT甲级满分必备刷题技巧_浒鱼鱼的博客-优快云博客_pat刷题 PAT甲级真题 PAT甲级真题_ZXX

青少年趣味编程 6304

影刀RPA:轻松搞定Excel表格自动化操作

影刀RPA是一款功能强大的自动化工具,通过模拟人类操作实现各种重复性任务的自动化。零代码操作:通过拖拽式流程设计器,无需编程基础即可快速上手。功能丰富:提供丰富的组件库,涵盖文件操作、数据处理等多种功能。高效稳定:支持多任务并行,确保任务的高效执行和稳定性。支持Python语法:内置数据表格,支持Python语法,对新手友好,同时具备循环功能。通过影刀RPA,您可以轻松实现Excel表格的拆分、列数据合并和归档工作的自动化。这不仅节省了手动操作的时间,还能确保数据处理的高效和准确,提升工作效率和管理水平。

watwrmoon的博客 2560

离散数学期末复习笔记【精华版】

文章目录前言一、????理逻辑1. 命题逻辑2. 等值演算3. 主合取范式、主析取范式4. 【题】推理证明5. 辖域、自由变元、约束变元二、????合1. 环和、环积,幂集,笛卡尔乘积三、 ????????关系1. 自反、对称、传递2&3. 合成运算,逆关系、闭包4. 哈斯图、上下界、偏序5. 等价关系、划分四、????1. 幺元(么元、单位元)、零元、逆元,半群、群、阿尔贝群、独异点、循环独异点2. 【题】由表判断3. 【题】证明五、????论1. 简单图、平凡图、多重图、子图、补图、出度、入度、

林大夕可的博客 17万+

PAT (Advanced Level) 1012. 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 - Eng

兔子哥哥的博客 1860

GD32F105RBT6 keil工程模板

创建GD32F105RBT6的keil初始基础工程,未来的所有外设驱动都是基于这个基础工程进行扩展。

RMDYBW的博客 1930

PAT (Advanced Level) Practice 1012 The Best Rank (25分)

1012 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 Lin...

一起加油 5550

vue3:实现ECharts3D地图详细示例,echarts实现3D地图map3D,vue3如何利用echarts绘制3d地图立体城市省市地区分布,可视化数据大屏3D炫酷中国地图(复制源码,开箱即用)

echarts实现中国地图记录篇之3D地图,Echarts地图之——如何让地图显示出3d感,【3d地图】vue中使用echarts geo3D,echarts实现某个市3D地图展示,vue3中使用echarts实现中国地图,3D地图图表,echarts实现3D地图——map3D,数据大屏3d地图,vue3+echarts绘制中国地图,3D地图,省、市、县,【3d地图】vue3中使用echarts geo3D,echarts实现某个市3D地图展示,ECharts3D地图(详细示例——附有具体注释),echar

✅ 精选推荐文章 3672

❤️爆肝十二万字《python从零到精通教程》,从零教你变大佬❤️(建议收藏)

文章目录强烈推荐系列教程,建议学起来!!一.pycharm下载安装二.python下载安装三.pycharm上配置python四.配置镜像源让你下载嗖嗖的快4.1pycharm内部配置4.2手动添加镜像源4.3永久配置镜像源五.插件安装(比如汉化?)5.1自动补码神器第一款5.2汉化pycharm5.3其它插件六.美女背景七.自定义脚本开头八、这个前言一定要看九、python入门十、python缩进十一、Python注释1.单行注释2.多行注释十二、Python 变量1.变量定义理解2. 变量名命名3. 分

全栈川川 26万+

1012. The Best Rank (25)-PAT甲级真题

1012. 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 Line...

柳婼 の blog 5126

基于uniapp开发PDA扫码枪APP:实现RFID批量扫描读取功能

基于uniapp的PDA扫码枪APP开发实战,实现高效RFID读取功能,uniapp整合PDA硬件的实践分享,基于uniapp的PDA端RFID批量扫描方案开发

商务合作 / 项目定制 / 学习交流。个人vx:lovely_wml 1万+

PAT 甲级 1012 The Best Rank (25分) 排序

PAT 甲级 1012 The Best Rank (25分) 排序

星辰不问 244

AI爬虫:一文讲通AI爬虫技术和原理,及34个AI爬虫工具推荐

AI 爬虫 是一种结合了传统网络爬虫技术和人工智能(AI)技术的工具,能够更智能、高效地从网页中提取和处理数据。与传统爬虫相比,AI 爬虫能够更好地处理动态内容、复杂网页结构以及非结构化数据,同时具备数据清洗、分类、情感分析等高级功能。

数据知道的博客 1万+

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

PAT 甲级 1012 The Best Rank

PAT 甲级 1012 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 enc

Jasonare的博客 395

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

PAT 甲级 1012  The Best Rank

1012 The Best Rank (25 point(s)) 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 (Calcul...

漫浸天空的雨色的备忘录~ 1071

最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版

Part-E1-SDIO-Specification-Ver4.00-Final-120220.pdf:最新的sdio 4.0 spec 协议标准 带书签 高清完整PDF版,包括SDIO 接口的外设,SDIO 接口官方协议等。

温度PID控制PLC程序

温度PID稳定控制程序,适用于欧姆龙PLC,对其他PLC也具有很大参考价值

PAT 甲级 1012(The Best Rank )

PAT 甲级 1012题目要求翻译代码思路 题目要求 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 en

qq_42865772的博客 197

PAT甲级 1012 The Best Rank (25 分) 排序 细节

PAT甲级 1012 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 Algrbra), and E - English. At th

weixin_46283740的博客 624

PAT甲题 1012 The Best Rank

PAT甲题 1012 The Best Rank题意回顾:个人解题思路:注意点:代码: 刚刚1011题,输出的全错,我寻思20分的题不至于吧 ,纳闷了半天发现题目让输出的’W’,我写成了’w’,所以细心是个good quality。废话不多讲,下面我们来看1012题。 题意回顾: 输入规格: 首先在第一行给出两个小于等于2000的正整数N,M; 其次按照顺序给出N个学生的学号、c语言成绩、数学成绩...

Yuhan的博客 339

PAT甲级 - 1012 The Best Rank (25 分)

题目链接:PAT甲级 - 1012 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 (...

196

【PAT甲级 排序】1012 The Best Rank (25 分) C++ 全部AC

题目 中规中矩的一道题。不太容易理解,但是理解之后写起来挺流畅的,没什么坑。 解题思路:题目会给出所有学生所有科目的成绩、想要看分学生的学号。 我们要先给这些学生单科成绩排序,算出它们的单科排名,存在Stu中 再依次输出想要看分的学生的最好成绩(最好成绩的学科 最好成绩的排名)。如果学号不存在,就输出N/A 题解 C++ #include<iostream> #include...

寒泉 2万+

PAT 甲级 1012 The Best Rank (25 分)

碰上这种题就头疼,不过看完别人的答案知道思路以后做起来倒也顺畅 Note: 1、数据结构 这题数据结构的选择很重要,看到一个很好的思路就是像数据库一样把每个学生当作一个结构体,在其中再使用数组表示学生的成绩和排名,并附加一个最好的排名方便查询 2、排序 先用sort排好序,遍历一遍逐个填入排名,然后再遍历一遍看有没有分数并列的情况,如果有就令他的排名等于前一名的排名。两个过程可以一次遍历完成。 3...

qq_39564678的博客 291

【PAT甲级题解记录】1012 The Best Rank (25 分)

问题描述 一个学生有三门课的成绩以及一个平均分成绩,分别用A、C、M、E表示。 每一个学生都有一个 best ranks – 最好排名,指的是四个成绩里取排名最高的成绩,求每个学生的最好排名以及是哪门成绩(若最好排名的成绩可以是不同的学科,按照ACME顺序优先输出)。 解题思路 一个学生有四个成绩,用一个结构体或者类存储会比较方便,又考虑到每个成绩都需要排名,结构体内应还有四个成绩的排名值、最好排名的课程号以方便查询。 对四个成绩分别排序以此初始化所有学生的四个成绩的排名值。(小技巧:利用stl的sor

retr0的博客 369
上一篇: [PAT甲级]1011. World Cup Betting (20)(世界杯投注)
下一篇: [PAT甲级]1013. Battle Over Cities (25)(图的遍历,统计强连通分量个数)
whl_program
博客等级 码龄11年 101粉丝 279原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值