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 - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- 【ES6基础】字符串扩展
4.字符串扩展 (1)for...of循环遍历. let foo = [1,2,3,4,5,6] for(let i of foo){ console.log(i); } 结果: (2)include ...
- SpringBoot电商项目实战 — 前后端分离后的优雅部署及Nginx部署实现
在如今的SpringBoot微服务项目中,前后端分离已成为业界标准使用方式,通过使用nginx等代理方式有效的进行解耦,并且前后端分离会为以后的大型分布式架构.弹性计算架构.微服务架构.多端化服务(多 ...
- VS2019 开发Django(十)------JavaScript与Django的数据交互
导航:VS2019开发Django系列 这一篇介绍如何使用BootStrap Table这个组件来绑定渲染数据, 1)先来看一下BootStrap Table是怎么绑定数据的. 通过数据属性 给定da ...
- Educational Codeforces Round 78 (Rated for Div. 2)
A题 给出n对串,求s1,是否为s2一段连续子串的重排,串长度只有100,从第一个字符开始枚举,sort之后比较一遍就可以了: char s1[200],s2[200],s3[200]; int ma ...
- CURL命令学习三
-I 只获取请求头 -k --insecure 每次SSL连接curl都需要验证是否安全.-k参数表示如果不安全也可以继续操作. -4 --ipv4 告诉curl只使用ipv4地址 -6 --ipv6 ...
- VS2017 无法修改代码编辑区的项背景颜色问题
以前都是好好的,安装 ClaudiaIDE: https://github.com/buchizo/ClaudiaIDE 之后也没啥问题,用着用着代码编辑区自定义的颜色就没有了,好几台电脑都是这样, ...
- 在 Spring Boot 项目中使用 activiti
新建springBoot项目时勾选activiti,或者在已建立的springBoot项目添加以下依赖: <dependency> <groupId>org.activiti& ...
- Hack the Breach 2.1 VM (CTF Challenge)
主机扫描: ╰─ nmap -p- -A 192.168.110.151Starting Nmap 7.70 ( https://nmap.org ) at 2019-08-29 09:48 CSTN ...
- 初识PMP PMBOK初解(指南第一章引论)
引论 1.1指南概述和目的 普遍认可:大多数时候是适用于大多数项目,价值和有效性已获得一致认可. 良好实践:知识.技能.工具和技术能够达到预期的商业价值和成果,提高很多项目成功的可能性. 确定过程.输 ...
- Linux下利用coredump技术追查进程崩溃原因
原文链接:https://blog.csdn.net/u014585564/article/details/68063269 最近项目中出现了一个问题,服务器端程序会突然崩溃退出,我们采取了cored ...