排序,水题
因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级A>C>M>E
那么按这个优先级顺序进行排序
每次排序前先求当前课程的排名
然后再与目前最好的排名比较、更新

至于查询,建立id与索引的映射即可。

#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>
using namespace std;
const int maxn=+;
int n,m;
map<string,int> maps;
struct Stu{
char id[];
int score[];
int ranks;
int best_rank=;
int c;
}stu[maxn]; bool cmp1(Stu a,Stu b){
return a.score[]>b.score[];
}
bool cmp2(Stu a,Stu b){
return a.score[]>b.score[];
}
bool cmp3(Stu a,Stu b){
return a.score[]>b.score[];
}
bool cmp4(Stu a,Stu b){
return a.score[]>b.score[];
} void solveRanks(int k){
stu[].ranks=;
if(stu[].ranks<stu[].best_rank){
stu[].best_rank=stu[].ranks;
stu[].c=k;
}
for(int i=;i<n;i++){
if(stu[i].score[k]==stu[i-].score[k]){
stu[i].ranks=stu[i-].ranks;
}
else{
stu[i].ranks=i+;
}
if(stu[i].ranks<stu[i].best_rank){
stu[i].best_rank=stu[i].ranks;
stu[i].c=k;
}
}
}
int main()
{
scanf("%d %d",&n,&m);
for(int i=;i<n;i++){
scanf("%s %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[])/;
}
sort(stu,stu+n,cmp4);
solveRanks(); sort(stu,stu+n,cmp1);
solveRanks(); sort(stu,stu+n,cmp2);
solveRanks(); sort(stu,stu+n,cmp3);
solveRanks(); string str;
for(int i=;i<n;i++){
str=stu[i].id;
maps[str]=i+;
}
char course[]={'C','M','E','A'};
for(int i=;i<m;i++){
cin>>str;
int idx=maps[str]-;
if(idx==-)
printf("N/A\n");
else
printf("%d %c\n",stu[idx].best_rank,course[stu[idx].c]);
}
return ;
}

PAT甲题题解-1012. The Best Rank (25)-排序水题的更多相关文章

  1. PAT甲题题解-1062. Talent and Virtue (25)-排序水题

    水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...

  2. PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚

    n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...

  3. PAT甲题题解-1125. Chain the Ropes (25)-贪心水题

    贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...

  4. PAT甲题题解-1052. Linked List Sorting (25)-排序

    三个注意点: 1.给出的n个节点并不一定都在链表中 2.最后一组样例首地址即为-1 3.输出地址的时候一直忘记前面要补0... #include <iostream> #include & ...

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

  6. 1012 The Best Rank (25分) vector与结构体排序

    1012 The Best Rank (25分)   To evaluate the performance of our first year CS majored students, we con ...

  7. PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题

    题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...

  8. PAT甲题题解-1058. A+B in Hogwarts (20)-大水题

    无语,这种水题还出,浪费时间,但又不得不A... #include <iostream> #include <cstdio> #include <algorithm> ...

  9. HDU排序水题

    1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...

随机推荐

  1. MMIO----Wav格式文件解析

    DirectSound只支持Wav格式的音频文件,在创建次缓冲区之前需要先确定播放的Wav音频数据的格式.如果是从本地Wav文件播放,则需要先读出它的数据格式. 1. Wav音频格式布局 Wav是WA ...

  2. 'javac' 不是内部或外部命令,也不是可运行的程序

    今天在命令行中运行javac命令时发现 但是运行java命令却可以 查找jdk的安装路径发现,安装目录里面同时有jdk的文件夹和jre的文件夹 查看了jdk的目录发现jdk目录中也有一个jre文件夹 ...

  3. [python]如何理解uiautomator里面的 instance 及使用场景

    通过uiautomatorviewer打开之后,需要通过对某个控件进行操作,但在当前界面中该控件所有属性无法唯一(其它控件属性也是一样),这个时候就需要借助实例(instance)来进行区分,inst ...

  4. 【Ansible 文档】【译文】配置文件

    这里说明一下配置文件的内容,原文地址:http://docs.ansible.com/ansible/latest/intro_configuration.html 这个与[Ansible 文档]配置 ...

  5. Codeforces Round #503 Div. 2

    时间相对来说还是比较合适的,正好放假就可以打一打啦. A. New Building for SIS:http://codeforces.com/contest/1020/problem/A 题意概述 ...

  6. Shell脚本查询进程存活信息

    脚本代码如下: pid=`cat $2` function status_job(){ pcount=`ps -ef |grep $pid |grep -v grep |wc -l` if [ $pc ...

  7. 智能家居 (2)手机一键自配置APP

    说明 本教程主要记录APP端一键自配置功能+TCP/IP通信 0配套使用单片机烧录 /* 文件名称:smartconfig.ino 功能:ESP8266快速配置功能 作者:www.doit.am 日期 ...

  8. 理解ASP.NET的IDataReader

    理解ASP.NET的IDataReader ADO.NET DataReader对象可以从数据库中检索只读.只进的数据流.因为每次在内存中的数据只有一行,所以使用DataReader可提高应用程序的性 ...

  9. 几个PHP读取整个文件的函数readfile()、fpassthru()和file()

    2.7.4   读取整个文件:readfile().fpassthru()和file()除了可以每次读取文件一行外,还可以一次读取整个文件.PHP提供了4种不同的方式来读取整个文件.第一种方式是rea ...

  10. Linux 内核开发 - 内核定时器

    时间差的度量 系统的定时器硬件以固定的频率产生时钟中断,产生始终中断的间隔以HZ 常量来决定,通常在50~1200之间,x86默认是1000.HZ能够依据不同的内核来配置. Linux 採用jiffi ...