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 - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- 基于TCP协议之socket编程
#服务端 #导入一个socket模块 import socket #想象成买手机打电话:socket.SOCK_STREAM 表示建立tcp连接 ,udp连接socket.SOCK_DGRAM #买了 ...
- 面向对象的进阶(item系列,__new__,__hash__,__eq__)
面向对象的进阶(item系列,__new__,__hash__,__eq__) 一.item系列 getitem.setitem.delitem(操作过程达到的结果其实就是增删改查) class ...
- Internet History,Technology,and Security - History: Commercialization and Growth(Week4)
Explosive Growth of the Internet and Web The Year of the Web 正如你所知道的,1994年是网络之年.1994年,NCSA的一位员工离职并建立 ...
- jquery获取表单中的数据
<form> <input name="username" type="text"/&g ...
- Delphi解析修改Json文件,基于superobject.pas(ISuperObject)
在经过一系列的波折后,还是觉得delphi读取并修改json文件来的方便: 在网络上找到一个delphi的三方库ISuperObject,添加到项目后直接引用就行: 下载地址 ISuperObject ...
- JS---案例---左右焦点轮播图(tb)
案例---左右焦点轮播图(tb) <!DOCTYPE html> <html lang="en"> <head> <meta charse ...
- 「SAP技术」SAP VL02N 执行批次拆分报错,说不允许批次拆分?
1,如下新建的DN 80017843,storage location 字段值为空.VL02N 试图去做批次拆分失败,系统报错说,Batch split is not permitted for ma ...
- Cesium专栏-terrain地形、3dtiles模型、gltf模型 高度采样
在Cesium中,对于terrain地形.3dtiles模型.gltf模型的高度采样是一个很基本的功能,基于此,可以做一些深度应用,而Cesium已经帮我们提供了相应的API,在这里,我帮大家总结一下 ...
- 一 、爬虫的认识与http
一 .爬虫的认识与http 互联网应用架构 一般采用c/s架构,b/s架构或者m/s架构 c/s 即 client server 客户端 服务端 b/s 即 browser server 浏览器 服 ...
- python程序员面试高概率会遇到的技术问题
本篇只列举会问到的技术问题.其他的问题会在另一篇文章多年职场老狗的面试经验提到. 1. TCP三次握手和四次挥手的过程 2.HTTP协议的状态码 3.讲一下自己用过的设计模式 4.python的多线程 ...