博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
PAT---A1012. The Best Rank (25)
阅读量:4005 次
发布时间:2019-05-24

本文共 3197 字,大约阅读时间需要 10 分钟。

题目要求:

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

参考代码:

#include 
#include
#include
using namespace std;struct student{ int ID; int grade[4];//用来存储平均分和C,M,E的分数}stu[2010];//用来控制输出,因为输出的优先级顺序而采用这种数组的构造方法,A>C>M>Echar out[4] = {
'A','C','M','E'};//rank1[ID][0]为学号为ID的学生的平均分的排名int rank1[1000000][4] = {
0};int now = 0;//按照从高到低构造cmp函数,详细的比较函数构造方法参考上篇博文:PAT---A1062. Talent and Virtue (25)bool cmp(student a,student b){ return a.grade[now]>b.grade[now];}int main(){ int M,N; cin >> N>>M; for(int i=0;i

本题使用学生的ID作为数组下标,如果学生的ID过长,则数组的长度可能过大,这时我们可以采用更一般的方法。

一般方法的解题思路:

解题思路就是:我们在学生的信息,也就是创建的结构体中增加了一个额外的附加信息用来标注结构体,就是order,order用来表示结构体的序列号。因为经过sort排序后,stu[]数组的顺序完全被改变,所以只有使用order来标识每一个学生,这时我们使用一个新的数组即rank1[][]这个二重数组来表示一个学生的排名,rank1[0]表示序号为0的学生,所以rank1[0][0]表示序号为0的学生的平均分在班级的排名,rank1[0][1]表示序号为0的学生的C在班级的排名。。。。。。然后根据输入的学号检索到此学号对应的order,再输出这个order的排名中最小的课

#include 
#include
#include
using namespace std;struct student{ int order; int ID; int grade[4];//用来存储平均分,C,M,E的分数}stu[2010];//用来控制输出,因为输出的优先级顺序而采用这种数组的构造方法,A>C>M>Echar out[4] = {
'A','C','M','E'};//rank1[0][0]为order是0的学生的平均分所占的名次int rank1[2010][4] = {
0};int now = 0;//按照从高到低构造cmp函数,详细的比较函数构造方法参考上篇博文:PAT---A1062. Talent and Virtue (25)bool cmp(student a,student b){ return a.grade[now]>b.grade[now];}int main(){ int M,N; cin >> N>>M; for(int i=0;i

转载地址:http://rbzfi.baihongyu.com/

你可能感兴趣的文章
在Idea中使用Eclipse编译器
查看>>
idea讲web项目部署到tomcat,热部署
查看>>
优化IDEA启动速度,快了好多。后面有什么优化点,会继续往里面添加
查看>>
JMeter 保持sessionId
查看>>
IDEA Properties中文unicode转码问题
查看>>
Idea下安装Lombok插件
查看>>
zookeeper
查看>>
Idea导入的工程看不到src等代码
查看>>
技术栈
查看>>
Jenkins中shell-script执行报错sh: line 2: npm: command not found
查看>>
8.X版本的node打包时,gulp命令报错 require.extensions.hasownproperty
查看>>
Jenkins 启动命令
查看>>
Maven项目版本继承 – 我必须指定父版本?
查看>>
Maven跳过单元测试的两种方式
查看>>
通过C++反射实现C++与任意脚本(lua、js等)的交互(二)
查看>>
利用清华镜像站解决pip超时问题
查看>>
[leetcode BY python]1两数之和
查看>>
微信小程序开发全线记录
查看>>
Centos import torchvision 出现 No module named ‘_lzma‘
查看>>
网页设计里的浮动 属性
查看>>