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 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:
Student ID 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个学生的3门科目的分数,平均分可以通过3门成绩计算得到,这样就会有4种排名C(C Programming Language)、M(Mathematics)、E(English)、A(Average),对于K次查询,给一个学生的ID,输出该学生在4种排名中最好的排名和排名方式,如果在多种排名方式中的排名相同,那么按照A>C>M>E的顺序输出,如果ID不存在
输出N/A。
解题思路:这个题已经有点成绩查询系统的意思了,核心是排序,需要注意的一点是排名并列应该是1、1、3、4、5而不是1、1、2、3、4。
#include<cstdio>
#include<string>
#include<iostream>
#include<algorithm>
using namespace std;
struct student{
int id;
int best;
int score[];
int ranks[];
}stu[];
int vis[];
int flag;
int cmp(student A,student B)
{
return A.score[flag]>B.score[flag];
} int main()
{
int n,m,id,i,j,best,temp;
char c[]={'A','C','M','E'};
scanf("%d%d",&n,&m);
for(i=;i<n;i++)
{
scanf("%d%d%d%d",&stu[i].id,&stu[i].score[],&stu[i].score[],&stu[i].score[]);
stu[i].score[]=(stu[i].score[]+stu[i].score[]+stu[i].score[])/3.0;//平均分
}
for(flag=;flag<=;flag++)//确定排名,保存在不同flag下的排名
{
sort(stu,stu+n,cmp);
stu[].ranks[flag]=;
for(i=;i<n;i++)
{
stu[i].ranks[flag]=i+;
if(stu[i].score[flag]==stu[i-].score[flag])//成绩相同。排名将会并列
{
stu[i].ranks[flag]=stu[i-].ranks[flag];
}
}
}
for(i=;i<n;i++)//确定每个人在4种排名方式下的最好排名
{
vis[stu[i].id]=i+;//序号
stu[i].best=;
int mins=stu[i].ranks[];
for(j=;j<=;j++)
{
if(stu[i].ranks[j]<mins)
{
mins=stu[i].ranks[j];
stu[i].best=j;
}
}
}
for(i=;i<m;i++)
{
scanf("%d",&id);
temp=vis[id];
if(temp)
{
best=stu[temp-].best;
printf("%d %c\n", stu[temp-].ranks[best], c[best]);
}
else
{
printf("N/A\n");
}
}
return ;
}
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 ...
- PAT甲级1012. The Best Rank
PAT甲级1012. The Best Rank 题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同 ...
- PAT甲 1012. The Best Rank (25) 2016-09-09 23:09 28人阅读 评论(0) 收藏
1012. The Best Rank (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 1012 The Best Rank (25分) vector与结构体排序
1012 The Best Rank (25分) To evaluate the performance of our first year CS majored students, we con ...
- 1012 The Best Rank (25 分)
1012 The Best Rank (25 分) To evaluate the performance of our first year CS majored students, we cons ...
- PAT 1012
1012. The Best Rank (25) To evaluate the performance of our first year CS majored students, we consi ...
- 浙大pat 1012题解
1012. The Best Rank (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To eval ...
- 1012 The Best Rank
1012 The Best Rank 1. 注意点 一名同学同样排名下的科目优先级问题 不同同学分数相同时排名相同,注意 排名不是 1 1 2 3 4 这种, 而是 1 1 3 4 5 注意到有些同学 ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- ssm整合——Mybatis配置(1)
mybatis搭建-基于注解 1. 环境准备 1.1 新建maven的webapp项目 1.2 新建必要的目录和文件 1.3 文件配置 pom.xml junit默认创建是4.11,手动改成4.12 ...
- CodeForces - 1059C Sequence Transformation (GCD相关)
Let's call the following process a transformation of a sequence of length nn. If the sequence is emp ...
- create-react-app 超级慢的解决方法
create-react-app超级慢的解决方法 在操作官方实例Create React App时,需要执行指令: create-react-app my-app 来创建一个新的React应用.由于某 ...
- 学习Python编程技术的流程与步骤,自学与参加培训学习都适用
一.清楚学习目标 无论是学习什么知识,都要有一个对学习目标的清楚认识.只有这样才能朝着目标持续前进,少走弯路,从学习中得到不断的提升,享受python学习计划的过程. 虽然目前的编程语言有很多,但是 ...
- Wonder发布v1.1正式版本,新增资产预览、脚本、AssetBundle等
更新说明 本次版本重点增加了脚本组件,并且实现了类似于unity的AssetBundle,支持动态加载场景和资源. 相关链接 官网 Wonder官方QQ群: 106047770 相关资料 Wonder ...
- uni-app实现多端开发
多端开发,听名字就感觉不一样,一套代码.多端使用,适用于各个平台.市面上很多关于多端开发的框架,比较常用,流行的框架 uni-app,Chameleon(变色龙),taro这些,都可以支持多端,一套代 ...
- 爬虫(九):python操作MySQL、MongoDB
1. python操作MySQL 1.1 MySQL基础 在java基础部分就写过了. https://www.cnblogs.com/liuhui0308/p/11891844.html 1.2 p ...
- IO测试工具 - 用于IO测试 ; linux benchmarks
IO测试工具,用于磁盘IO测试,下面进行使用列表进行记录: iozone fio dd ioping iotop iostat bonnie++ crystalDisk Atto as-ssd-ben ...
- python 打飞机项目 (实战一)
第一步定义 main 函数: # -*- coding=utf-8 -*- import pygame,time from Plane import Plane from pygame.locals ...
- SpringCloudConfig对称加密 yml配置文件while parsing a block mapping
错误的配置!!! #-----------------db------------------ mybatis: type-aliases-package: com.book.product.pojo ...