PAT The Best Rank[未作]
1012 The Best Rank (25)(25 分)
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
//emm,这个没写出来,看了别人的之后恍然大悟,我应该过几天之后再自己写出来。
代码来自:https://www.liuchuo.net/archives/2207
#include <cstdio>
#include <algorithm>
using namespace std;
struct node {
int id, best;
int score[], rank[];
}stu[];
int exist[], flag = -;//厉害了,不用map,用哈希数组。
bool cmp1(node a, node b) {return a.score[flag] > b.score[flag];}
//我的天,这个flag可以默认传进来。。
int main() {
int n, m, id;
scanf("%d %d", &n, &m);
for(int 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 + 0.5;
//要四舍五入,所以+0.5后取整。
}
for(flag = ; flag <= ; flag++) {
sort(stu, stu + n, cmp1);
//有可能按照这个排出来之后,连续好几个数都相等。
stu[].rank[flag] = ;
for(int i = ; i < n; i++) {
stu[i].rank[flag] = i + ;//理论上来说先赋值为i+1,再判断和前边相等,那么就再更新。
if(stu[i].score[flag] == stu[i-].score[flag])
stu[i].rank[flag] = stu[i-].rank[flag];//那么就直接赋值相等就可以了。
}
}
for(int i = ; i < n; i++) {
exist[stu[i].id] = i + ;
stu[i].best = ;
int minn = stu[i].rank[];
for(int j = ; j <= ; j++) {//这个也是通过循环找到。
if(stu[i].rank[j] < minn) {
minn = stu[i].rank[j];
stu[i].best = j;
}
}
}
char c[] = {'A', 'C', 'M', 'E'};
for(int i = ; i < m; i++) {
scanf("%d", &id);
int temp = exist[id];
if(temp) {
int best = stu[temp-].best;
printf("%d %c\n", stu[temp-].rank[best], c[best]);
} else {
printf("N/A\n");
}
}
return ;
}
//看这个代码受到了很多启发:1.如果出现分数名相等的情况,该怎么处理?for循环写的非常好,并且根据题目特点使用了哈希数组存储id对应的下标,但是因为牛客网上的id中包含字母,所以就通不过,这个地方可以改进,明天我来试一试。
PAT The Best Rank[未作]的更多相关文章
- PAT Battle Over Cities [未作]
1013 Battle Over Cities (25)(25 分) It is vitally important to have all the cities connected by highw ...
- PAT A1012 Best Rank(25)
题目描述 To evaluate the performance of our first year CS majored students, we consider their grades of ...
- PAT甲级 并查集 相关题_C++题解
并查集 PAT (Advanced Level) Practice 并查集 相关题 <算法笔记> 重点摘要 1034 Head of a Gang (30) 1107 Social Clu ...
- 借助Process Explorer定位断电未保存的录音文件
话说某大神(大婶)开会常偷懒,用Windows自带的录音机进行录音并用记事本记录会议精要却没有点击Ctrl+S的习惯,结果就给我找了今天的难题.(之前都是Office的自动保存在哪里……) 还是一样, ...
- Java & Android未捕获异常处理机制
一.背景 无论是Java还是Android项目,往往都会用到多线程.不管是主线程还是子线程,在运行过程中,都有可能出现未捕获异常.未捕获异常中含有详细的异常信息堆栈,可以很方便的去帮助我们排查问题. ...
- PAT(B) 1059 C语言竞赛(C)
题目链接:1059 C语言竞赛 (20 point(s)) 题目描述 C 语言竞赛是浙江大学计算机学院主持的一个欢乐的竞赛.既然竞赛主旨是为了好玩,颁奖规则也就制定得很滑稽: 冠军将赢得一份" ...
- PAT题目AC汇总(待补全)
题目AC汇总 甲级AC PAT A1001 A+B Format (20 分) PAT A1002 A+B for Polynomials(25) PAT A1005 Spell It Right ( ...
- 未释放资源的教训,开发MongoDB连接一定要关闭连接
废不少工夫将数据存储,全部迁移至mongodb,未作大量改动则是主因. 但遇到奇怪的现象. 程序跑起不久后,mongodb即假死,另起客户端想登陆mongodb都不成. 要重启mongodb服务器才好 ...
- 转债---Pregel: A System for Large-Scale Graph Processing(译)
转载:http://duanple.blog.163.com/blog/static/70971767201281610126277/ 作者:Grzegorz Malewicz, Matthew ...
随机推荐
- Git学习之Git 暂存区
============================= 修改文件后是否可以直接提交 ============================ (1) 向文件中追加一行内容 $ echo &quo ...
- pace.js简介
Pace.js – 超赞的页面加载进度自动指示和 Ajax 导航效果 在页面中引入 Pace.js 和您所选择主题的 CSS 文件,就可以让你的页面拥有漂亮的加载进度和 Ajax 导航效果.不需要挂接 ...
- java框架---->commonmark的使用(一)
commonmark-java是一个Markdown 解析器,一个基于CommonMark规范解析和渲染Markdown文本的Java库.偶尔要回头看看,否则永远都在追寻,而不知道自己失去了什么. c ...
- 【大数据系列】基于MapReduce的数据处理 SequenceFile序列化文件
为键值对提供持久的数据结构 1.txt纯文本格式,若干行记录 2.SequenceFile key-value格式,若干行记录,类似于map 3.编写写入和读取的文件 package com.slp; ...
- 【大数据系列】安装Ambari
一.Ambari简介 The Apache Ambari project is aimed at making Hadoop management simpler by developing soft ...
- mybatis generator如何定制JavaTypeResolver,使smallint类型的数据库字段在po中的类型为Integer?
一.问题概述 忙了一段时间的jenkins持续集成,又要开始开发任务了.这两天在用mybatis generator来逆向生成dao层工程. 其中一个问题在于,组长在设计表的时候,不少枚举使用了sma ...
- Nginx写IO占用高故障处理
文章来源:<https://www.centos.bz/2015/04/handle-nginx-write-io-problem/> 故障现象 突然收到一台服务器负载过高告警,紧接着网站 ...
- .sh 的运行
cat *.sh 看一下你的那个sh文件 看第一行是#!/bin/bash 还果 #!/bin/sh 如果是/bin/bash就执行 bash your.sh 如果是/bin/sh 就执行 sh yo ...
- 惠普hp服务器通过iLO接口远程安装操作系统
我们以hp proliant sl210t的机器为例,我们在配置好iLO接口的远程管理后,我们便可以通过iLO进行操作系统的安装 关于惠普服务器的iLO配置,可参笔者的另一篇文章<关于hp pr ...
- OSI互联数据包封装与解封装过程
当我们在七层协议最上层,主机A想和其它主机通信, 比如telnet到主机B,各层都为数据打包后再封装上自己能识别的数据标签,现在我们只说四层以下的通信过程. .当一个高层的数据包到达传输层,由于tel ...