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 - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
随机推荐
- Sockit 硬件接口编程——点亮一个LED
1.话不多说上代码 #include <stdio.h> #include <stdlib.h> #include <string.h> #include < ...
- 《Dotnet9》建站-本站使用的什么主题?
时间如流水,只能流去不流回! 点赞再看,养成习惯,这是您给我创作的动力! 本文 Dotnet9 https://dotnet9.com 已收录,站长乐于分享dotnet相关技术,比如Winform.W ...
- [转]JVM参数使用手册
内存分配相关 Xms 英文释义:Initial heap size(in bytes) 中文释义:堆区初始值 使用方法:-Xms2g 或 -XX:InitialHeapSize=2048m Xmx 英 ...
- NPOI 设置下拉列表
HSSFWorkbook workbook = new HSSFWorkbook();//创建工作簿 ISheet sheet = workbook.CreateSheet();//创建sheet页 ...
- wx-一个简单页面
一个具有顶部,底部和中间的html页面,但没有js <view class="root"> <!-- 标签栏的页签 固定高度 --> <view cl ...
- selenium的安装、报错和解决
selenium是的作用是模拟点击浏览器上的按钮,配合一个无头浏览器就可以快速解决一些前端需要加解密的功能. 第一步pip install selenium安装的第一步就是用pip把模块下载回来. ...
- iOS----------证书的制作
https://developer.umeng.com/docs/66632/detail/66748#createappid Certificates-> 卫生许可证 identifiers ...
- ORA-27140: attach to post/wait facility failed
Errors in file /home/u01/app/oracle/diag/rdbms/hnybdb21/hnybdb211/trace/hnybdb211_j000_143099.trc:OR ...
- Leetcode92: Reverse Linked List II 翻转链表问题
问题描述 给定一个链表,要求翻转其中从m到n位上的节点,返回新的头结点. Example Input: 1->2->3->4->5->NULL, m = 2, n = 4 ...
- Get提交数据过大,tomcat报错,信息: Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors will be logged at DEBUG level
原因 get提交的数据过大,超过了默认值. 解决办法 get提交配置 设置tomcat的server.xml.找到我们启动的端口,一般是8080,增加maxHttpHeaderSize= " ...