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 ...
随机推荐
- vc获取当前进程CPU使用率
double GetCPUUserRate() { HANDLE hProcess=::GetCurrentProcess(); static DWORD s_dwTickCountOld = 0; ...
- javascript,object,IDispatchEx笔记
//js: var testObj=new Object; //com内部: testObj=Object::InvokeEx(wFlags==DISPATCH_CONSTRUCT); //注: // ...
- JSR规范
JSR是JavaSpecification Requests的缩写,意思是Java 规范提案.是指向JCP(Java Community Process)提出新增一个标准化技术规范的正式请求.任何人都 ...
- swiper.js 多图片页面的懒加载lazyLoading
swiper.js官网:http://www.swiper.com.cn/api/Images/2015/0308/213.html 设为true开启图片延迟加载,使preloadImages无效.需 ...
- php 导出导入excel
首先需要去官网https://github.com/PHPOffice/PHPExcel/下载PHPExcel,下载后只需要Classes目录下的文件即可. 链接: https://pan.baidu ...
- Maven单独构建多模块项目中的单个模块
Maven单独构建多模块项目中的单个模块 说明: 1.可能存在的场景,多模块项目没有互相引用,那么此时可以单独构建单个项目,指定到子模块的pom.xml文件即可完成编译. 2.如果多模块项目各自都 ...
- [luogu3198] 玩具装箱
题面 最近在搞dp, 发现自己的dp还是太弱了, 做的题比较少, 也有一些东西没学, 这道题算是我独立做的第一道斜率优化dp, 写篇题解纪念一下吧. dp式比较简单, 就是一个线性的dp, 设 ...
- Mac OS 上配置java开发环境
在开始本学期的java课程前,我需要先为自己的电脑配置好Java的开发环境.由于电脑是mac操作系统,所以教材上的教程对我并不管用,于是乎开始动手自己查阅网上资料来解决. 1.安装JDK 1.访问Or ...
- WebView之加载网页时增加进度提示
上一节讲了一些webview的基本使用以及在记载网页时如何屏蔽掉第三方浏览器,使我们自己开发的程序成为一个微型浏览器.那么这一节将一下在webView加载网页的过程中如何加上进度提示.效果图如下: 主 ...
- float与double的范围和精度以及大小非零比较
1. 范围 float和double的范围是由指数的位数来决定的. float的指数位有8位,而double的指数位有11位,分布如下: float: 1bit(符号位) 8bits(指数位) ...