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 ...
随机推荐
- kafka---->kafka的使用(一)
今天我们来学习一下kafka的简单的使用与配置.世上有可以挽回的和不可挽回的事,而时间经过就是一种不可挽回的事. kafka的安装配置 一.kafka的使用场景 活动跟踪:网站用户与前端应用程序发生交 ...
- C++中三种创建对象的方法【转】
我们都知道C++中有三种创建对象的方法,如下: #include <iostream> using namespace std; class A { private: int n; pub ...
- intellij2016.03激活
激活的时候采用server的方式 :http://jetbrains.tech
- 微信小程序插件内页面跳转和参数传递(转)
在此以插件开发中文章列表跳传文章详情为例. 1.首先在插件中的文章列表页面wxml中绑定跳转事件. bindtap='url' data-id="{{item.article_id}}&qu ...
- 字符乱码 导致 ORA-12899: value too large
问题场景: 1.创建测试表 create table t01(name varchar2(30)) 2.插入数据 SQL> insert into t01 (name) values('所有分销 ...
- LeetCode 23 Merge k Sorted Lists(合并k个有序链表)
题目链接: https://leetcode.com/problems/merge-k-sorted-lists/?tab=Description Problem: 给出k个有序的list, 将其进行 ...
- git服务器
1 关于版本控制版本控制是一种记录一个或若干文件内容变化,以便将来查阅特定版本修订情况的系统.有以下三种版本控制系统:1. 本地版本控制系统许多人习惯用复制整个项目目录的方式来保存不同的版本,或许还会 ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十:PS/2模块④ — 普通鼠标
实验十:PS/2模块④ - 普通鼠标 学习PS/2键盘以后,接下来就要学习 PS/2 鼠标.PS/2鼠标相较PS/2键盘,驱动难度稍微高了一点点,因为FPGA(从机)不仅仅是从PS/2鼠标哪里读取数据 ...
- SVN服务端安装
1 首先安装SVN和Subversion. 安装文件可自行百度. 2 在服务端创建版本库. 我的安装目录是c:\Program Files(x86)\Subversion. 安装完成后在安装目录下sh ...
- CentOS6.5 下将 Python2.6.6 升级到Python3.5
一. 从Python官网到获取Python3的包, 切换到目录/usr/local/src #wget https://www.python.org/ftp/python/3.5.1/Python-3 ...