PAT_A1012#The Best Rank
Source:
Description:
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 Algrbra), andE
- 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
andA
- 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 Specification:
Each input file contains one test case. Each case starts with a line containing 2 numbers N and M (≤), 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
andE
. Then there are M lines, each containing a student ID.
Output Specification:
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
Keys:
- 模拟题
Attention:
- 拿原数组排序去了,找错误找了半天,脑壳疼0,0
Code:
/*
Data: 2019-07-17 20:25:53
Problem: PAT_A101#The Best Rank
AC: 49:52 题目大意:
排名
输入:
第一行给出,学生总数N<=2e3,查询数M<=2e3
接下来N行,id,c,m,e
接下来M行,id
输出:
最好成绩,相应科目A>C>M>E
不存在N/A
*/ #include<cstdio>
#include<algorithm>
using namespace std;
const int M=1e4,H=1e7,N=;
struct node
{
int id;
int grade[N],rnk[N];
}info[M];
int mp[H]={},st[M],key;
char sub[N]={'A','C','M','E'}; bool cmp(const int &a, const int &b)
{
return info[a].grade[key] > info[b].grade[key];
} int main()
{
#ifdef ONLINE_JUDGE
#else
freopen("Test.txt", "r", stdin);
#endif int n,m,r,id;
scanf("%d%d", &n,&m);
for(int i=; i<=n; i++)
{
scanf("%d",&info[i].id);
mp[info[i].id]=i;
st[i]=i;
for(int j=; j<N; j++)
scanf("%d", &info[i].grade[j]);
info[i].grade[]=info[i].grade[]+info[i].grade[]+info[i].grade[];
}
for(int i=; i<N; i++)
{
key=i;
sort(st+,st+n+,cmp);
for(int j=; j<=n; j++)
{
int pre=st[j-],now=st[j];
if(j== || info[pre].grade[i]!=info[now].grade[i])
r=j;
info[now].rnk[i]=r;
}
}
for(int i=; i<m; i++)
{
scanf("%d", &id);
if(mp[id]==)
{
printf("N/A\n");
continue;
}
int best=;
for(int j=; j<N; j++)
if(info[mp[id]].rnk[j]<info[mp[id]].rnk[best])
best=j;
printf("%d %c\n", info[mp[id]].rnk[best],sub[best]);
} return ;
}
PAT_A1012#The Best Rank的更多相关文章
- UVA, 10336 Rank the Languages
难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...
- [LeetCode] Rank Scores 分数排行
Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...
- rank()函数的使用
排序: ---rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4select scoreid, stu ...
- [转]oracle分析函数Rank, Dense_rank, row_number
oracle分析函数Rank, Dense_rank, row_number 分析函数2(Rank, Dense_rank, row_number) 目录 ==================== ...
- 分区函数Partition By的与row_number()的用法以及与排序rank()的用法详解(获取分组(分区)中前几条记录)
partition by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition by用于给结果集分组,如果没有指 ...
- Learning to rank 介绍
PS:文章主要转载自CSDN大神hguisu的文章"机器学习排序": http://blog.csdn.net/hguisu/article/details/79 ...
- R语言排序:sort(),rank(),order()示例
> x<-c(97,93,85,74,32,100,99,67) > sort(x) [1] 32 67 74 85 93 97 99 100 > order(x) [1] 5 ...
- [Machine Learning] Learning to rank算法简介
声明:以下内容根据潘的博客和crackcell's dustbin进行整理,尊重原著,向两位作者致谢! 1 现有的排序模型 排序(Ranking)一直是信息检索的核心研究问题,有大量的成熟的方法,主要 ...
- sqlserver 中row_number,rank,dense_rank,ntile排名函数的用法
1.row_number() 就是行号 2.rank:类似于row_number,不同之处在于,它会对order by 的字段进行处理,如果这个字段值相同,那么,行号保持不变 3.dense_rank ...
随机推荐
- “void * __cdecl operator new(unsigned int)”(??2@YAPAXI@Z) already defined in LIBCMTD.lib(new.obj)
转自VC错误:http://www.vcerror.com/?p=1377 问题描述: 当 C 运行时 (CRT) 库和 Microsoft 基础类 (MFC) 库的链接顺序有误时,可能会出现以下 L ...
- webstorm 插件安装
1.打勾的表示已经安装 2.没有安装的插件,可以在plugins搜索,在右边搜索结果里点install,然后重启webstorm 3.这里有常用插件 http://blog.csdn.net/xs20 ...
- EmWin 如何显示汉字 不用在文件中使用编码
1. Font Converter for emWin 生成C文件字库 1.1 新建文件 1.2 选择字体 1.3 为了减小C文件体积,这里只加入自己需要的汉字,先把所有字体取消选择. 1.4 新建一 ...
- Python Numpy线性代数操作
Python Numpy线性代数函数操作 1.使用dot计算矩阵乘法 import numpy as np from numpy import ones from __builtin__ import ...
- springMvc注册时图形验证码完整代码与详细步骤``````后续更新注册时对密码进行加密
第一使用 画图软件制作图片 ,文件名就是验证码 ------用户的实体类 import java.util.Date; public class Member { private in ...
- 深入了解line-height(各种单位总结1.5/150%/1.5em)
默认状态,浏览器使用1.0-1.2 line-height, 这是一个初始值.你可以定义line-height属性来覆盖初始值:p{line-height:140%} 你可以有5种方式来定义line- ...
- mybatis之增删改
前面三小节内容主要是针对查询操作进行讲解,现在对mybatis增删改进行演示. 由于每次建立工程比较复杂,可以参考第一节:mybatis入门来搭建一个简单的工程,然后来测试本节内容. 1.增 1.新增 ...
- Electron 常见问题
导读: 以下记录了作者在实践中遇到的问题和最后的解决方法,如果有错误或者更新更完美的解决方案,欢迎留言指正.交流. 1.jQuery/RequireJS/Meteor/AngularJS 的问题 jQ ...
- netease-cloud-music : 依赖: libqt5x11extras5 (>= 5.1.0) 但是它将不会被安装
修复一下依赖关系: sudo apt-get install -f #或者:sudo apt-get -f install 上面两条是修复依赖关系(depends)的命令,就是假如你的系统上有某个pa ...
- 【读书笔记】剑指offer
导语 所有的编程练习都在牛客网OJ提交,链接: https://www.nowcoder.com/ta/coding-interviews 九章算法的 lintcode 也有这本书的题目.https: ...