PAT甲题题解-1012. The Best Rank (25)-排序水题
排序,水题
因为最后如果一个学生最好的排名有一样的,输出的课程有个优先级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)-排序水题的更多相关文章
- PAT甲题题解-1062. Talent and Virtue (25)-排序水题
水题,分组排序即可. #include <iostream> #include <cstdio> #include <algorithm> #include < ...
- PAT甲题题解-1019. General Palindromic Number (20)-又是水题一枚
n转化为b进制的格式,问你该格式是否为回文数字(即正着写和倒着写一样)输出Yes或者No并且输出该格式又是水题... #include <iostream> #include <cs ...
- PAT甲题题解-1125. Chain the Ropes (25)-贪心水题
贪心水题,每次取最短的两个绳子合并,长度缩减成一半 #include <iostream> #include <cstdio> #include <algorithm&g ...
- PAT甲题题解-1052. Linked List Sorting (25)-排序
三个注意点: 1.给出的n个节点并不一定都在链表中 2.最后一组样例首地址即为-1 3.输出地址的时候一直忘记前面要补0... #include <iostream> #include & ...
- 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 ...
- 1012 The Best Rank (25分) vector与结构体排序
1012 The Best Rank (25分) To evaluate the performance of our first year CS majored students, we con ...
- PAT甲题题解-1036. Boys vs Girls (25)-找最大最小,大水题
题意:给出n个人的姓名.性别.ID.分数,让你找出其中哪个妹纸分数最高.哪个汉子分数最低.以及他们的差如果没有妹纸或者汉子,则对应输出Absent,差用NA代替. 就是for一遍找最大最小值,水题 # ...
- PAT甲题题解-1058. A+B in Hogwarts (20)-大水题
无语,这种水题还出,浪费时间,但又不得不A... #include <iostream> #include <cstdio> #include <algorithm> ...
- HDU排序水题
1040水题; These days, I am thinking about a question, how can I get a problem as easy as A+B? It is fa ...
随机推荐
- 第 13 章 文件输入/输出 (标准I/O)
/*-------------------------- count.c -- 使用标准 I/O --------------------------*/ #include <stdio.h&g ...
- hadoop集群为分布式搭建
1.准备Linux环境设置虚拟机网络 1.0点击VMware快捷方式,右键打开文件所在位置 -> 双击vmnetcfg.exe -> VMnet1 host-only ->修改 ...
- 常用npm 命令
npm 官方网站:npm的使用说明 安装模块 npm install 安装当前目录package.json文件中配置的dependencies模块 安装本地的模块文件 npm install ...
- 【js】实现继承的6种方法
1.原型链 基本思想:利用原型链让一个引用类型继承另一个引用类型的属性和方法. 让原型对象(B.prototype)等于另一个类型的实例(new A()), 即B.prototype = new A( ...
- 【2018暑假集训模拟一】Day1题解
T1准确率 [题目描述] 你是一个骁勇善战.日刷百题的OIer. 今天你已经在你OJ 上提交了y 次,其中x次是正确的,这时,你的准确率是x/y.然而,你最喜欢一个在[0; 1] 中的有理数p/q(是 ...
- JS获取客户端公网IP和IP地址
网上解决方案 1.通过搜狐接口 获取方式如下: //网页端引入脚本 <script type="text/javascript" src="http://pv.so ...
- Jmeter上传下载文件
每次使用时都会忘记,此处是存储网路上通用的方式. 1.上传文件 记得勾选“use multipart/form-data for post”,表明此请求包含文件信息.在信息请求头中,需加入“Con ...
- 学习C#(一)
赶紧好好学学自己的C#,,要不然要给做的东西说拜拜了,,,时间紧迫,,,真担心会食言..................... 在C#中以为只要类有构造方法,,,,原来结构也有 using Syste ...
- 通过HttpWebRequest调用webService
调用远端接口,向远端接口写入一个xml文件(loginLog为xml的字符串).关键方法如下: public object InsertAuditLog(string loginLog) { //Ws ...
- USB主机控制器ECHI
USB主机控制器ECHI 2017年10月24日 15:44:11 阅读数:239 1. 主机控制器(Host Controller) • UHCI: Universal Host Controlle ...