Source:

PAT A1012 The Best Rank (25 分)

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), 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 CME 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 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 CMand E. 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的更多相关文章

  1. UVA, 10336 Rank the Languages

    难点在于:递归函数和输出: #include <iostream> #include <vector> #include <algorithm> #include ...

  2. [LeetCode] Rank Scores 分数排行

    Write a SQL query to rank scores. If there is a tie between two scores, both should have the same ra ...

  3. rank()函数的使用

    排序: ---rank()over(order by 列名 排序)的结果是不连续的,如果有4个人,其中有3个是并列第1名,那么最后的排序结果结果如:1 1 1 4select scoreid, stu ...

  4. [转]oracle分析函数Rank, Dense_rank, row_number

    oracle分析函数Rank, Dense_rank, row_number 分析函数2(Rank, Dense_rank, row_number)   目录 ==================== ...

  5. 分区函数Partition By的与row_number()的用法以及与排序rank()的用法详解(获取分组(分区)中前几条记录)

    partition by关键字是分析性函数的一部分,它和聚合函数不同的地方在于它能返回一个分组中的多条记录,而聚合函数一般只有一条反映统计值的记录,partition by用于给结果集分组,如果没有指 ...

  6. Learning to rank 介绍

    PS:文章主要转载自CSDN大神hguisu的文章"机器学习排序":          http://blog.csdn.net/hguisu/article/details/79 ...

  7. 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 ...

  8. [Machine Learning] Learning to rank算法简介

    声明:以下内容根据潘的博客和crackcell's dustbin进行整理,尊重原著,向两位作者致谢! 1 现有的排序模型 排序(Ranking)一直是信息检索的核心研究问题,有大量的成熟的方法,主要 ...

  9. sqlserver 中row_number,rank,dense_rank,ntile排名函数的用法

    1.row_number() 就是行号 2.rank:类似于row_number,不同之处在于,它会对order by 的字段进行处理,如果这个字段值相同,那么,行号保持不变 3.dense_rank ...

随机推荐

  1. 未来-YLB-二手市场:二手市场

    ylbtech-未来-YLB-二手市场:二手市场 1.返回顶部 1. 二手市场是人们将闲置不用的物品集中起来进行交换.交易的场所.在二手市场中买卖二手物品,价格低廉.二手交易市场又称跳蚤市场.   中 ...

  2. 树状数据删除(TP5)

    应用场景:类似上图中树状菜单,选中一级菜单 点击上方删除按钮 所有子菜单删除 以下是代码截图(代码基于 TP5)

  3. JS的常用正则表达式 验证密码用户名等

    //校验是否全由数字组成 function isDigit(s) { var patrn=/^[0-9]{1,20}$/; if (!patrn.exec(s)) return false retur ...

  4. PHP数组循环遍历的几种方式

    PHP数组循环遍历 1.for循环 <?php //语法 for (init counter; test counter; increment counter) { code to be exe ...

  5. PHP中输出字符串(echo,print,printf,print_r和var_dump)的区别【转载】

    php中常见的输出语句 echo()可以一次输出多个值,多个值之间用逗号分隔.echo是语言结构(language construct),而并不是真正的函数,因此不能作为表达式的一部分使用. prin ...

  6. Redis源码编译安装

    介绍 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo写的key-value存储系统.Redis是一个开源的使用ANSI C语言编写.遵 ...

  7. CVE-2010-4258漏洞分析

    Nelson Elhage最近发现了一个内核设计上的漏洞, 通过利用这个漏洞可以将一些以前只能dos的漏洞变成可以权限提升的漏洞. 当fork一个进程在的时候, copy_process执行如下操作: ...

  8. Jsoup爬虫任务总结

    这两周由于公司需要大量数据爬取进数据库给用户展示素材,在不停的做爬虫工作,现在总算基本完成就剩清理数据的工作: 公司有一个采集器管理后台的项目,可以直接把爬虫代码打包成jar导入进去设置定时参数即可: ...

  9. 【java】读写文件

    不要吐槽我为啥不写try,catch. 默认的相对路径是在工作空间的目录下. 如图 import java.io.*; import java.util.*; public class filerw ...

  10. SpringBoot传递单一参数时@RequestParam和@RequestBody的区

    用SpringBoot框架做项目时,经常需要前端给后端传递参数,如果需要多条参数,通常的做法是把这些参数封装为一个对象来传递,前端用POST方式调用.但有时会遇到后端只需要一条参数(比如一个Strin ...