PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化
After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.
Input Specification:
Each input file contains one test case. For each case, the first line gives a positive integer N (≤105), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:
ID Score School
where ID is a string of 6 characters with the first one representing the test level: B stands for the basic level, A the advanced level and T the top level; Score is an integer in [0, 100]; and School is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that ID is unique for each testee.
Output Specification:
For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:
Rank School TWS Ns
where Rank is the rank (start from 1) of the institution; School is the institution code (all in lower case); ; TWS is the total weighted score which is defined to be the integer part of ScoreB/1.5 + ScoreA + ScoreT*1.5, where ScoreX is the total score of the testees belong to this institution on level X; and Ns is the total number of testees who belong to this institution.
The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.
Sample Input:
10
A57908 85 Au
B57908 54 LanX
A37487 60 au
T28374 67 CMU
T32486 24 hypu
A66734 92 cmu
B76378 71 AU
A47780 45 lanx
A72809 100 pku
A03274 45 hypu
Sample Output:
5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <string>
#include <vector>
#include <set>
#include <cctype>
using namespace std;
const int maxn=;
int n,m,k;
struct node{
string id;
int score;
string ins;
};
struct inst{
string insti;
int tws;
int score[]={,,};
int ns;
bool operator < (const inst& a)const{
if(tws>a.tws)return true;
else if(tws==a.tws){
if(ns<a.ns) return true;
else if(ns==a.ns){
return insti<a.insti?true:false;
}
else return false;
}
else return false;
}
};
int cnt;
map<string,inst> mp;
vector<inst> v;
int main(){
scanf("%d",&n);
for(int i=;i<n;i++){
string id,ins;
int score,tw=;
cin>>id>>score>>ins;
transform(ins.begin(), ins.end(), ins.begin(), ::tolower);
if(mp.find(ins)==mp.end()){
inst tmp;
tmp.insti=ins;
tmp.ns=;
//tmp.tws=tw;
if(id[]=='B'){
tmp.score[]=score;
}
else if(id[]=='A'){
tmp.score[]=score;
}
else{
tmp.score[]=score;
}
mp[ins]=tmp;
}
else{
inst tmp=mp[ins];
tmp.ns++;
if(id[]=='B'){
tmp.score[]+=score;
}
else if(id[]=='A'){
tmp.score[]+=score;
}
else{
tmp.score[]+=score;
}
mp[ins]=tmp;
}
}
printf("%d\n",mp.size());
int rank=;
for(auto it=mp.begin();it!=mp.end();it++){
inst tmp=it->second;
tmp.tws=tmp.score[]/1.5+tmp.score[]+tmp.score[]*1.5;
v.push_back(tmp);
}
sort(v.begin(),v.end());
printf("%d %s %d %d\n",rank,v[].insti.c_str(),v[].tws,v[].ns);
for(int i=;i<v.size();i++){
if(v[i].tws!=v[i-].tws) rank=i+;
printf("%d %s %d %d\n",rank,v[i].insti.c_str(),v[i].tws,v[i].ns);
}
}
注意点:排序题有sort的帮助还是比较简单的,虽然还是花了很久,调试了很久。还用到了map和vector,最开始想直接map里面排序,还写了结构体重载函数,发现map是根据第一个键值来排序的,那只好再保存到vector里,反正也要遍历一遍算tws。重载了<号就不用写cmp函数了。因为set和map自动排序是根据小于号判断两个结构体的大小,小的放前面,sort 排序不写cmp函数也是自动根据小于号有小到大排列。
第一个坑是最开始每读一个分数看他哪个等级就更新 tws,这样最后一个测试点答案错误,以为要用float,重新看了遍题,他是取整数部分,但不是每一个来取,而是对所有对应等级的总和取整,这就还需要保存一个总和值最后一起来算
第二个坑是结构体里面保存总和的数组没有显式初始化为0,算出来答案一直错误,需要手动初始化为0,就AC了
第三个注意点是字符串转大小写,用到 algorithm 里的 transform 函数,格式要记住
PAT A1141 PAT Ranking of Institutions (25 分)——排序,结构体初始化的更多相关文章
- PAT A1075 PAT Judge (25 分)——结构体初始化,排序
The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...
- PAT 甲级 1012 The Best Rank (25 分)(结构体排序)
题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...
- 【PAT甲级】1016 Phone Bills (25 分)(结构体排序)
题意: 输入24个正整数代表从0到23每个小时通话一分钟花费的美分.输入一个正整数N(<=1000),然后输入N组字符串,每个字符串包含客户的名字和通话的时刻以及打出或者挂断的状态. 按照字典序 ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)
1016 Phone Bills (25 分) A long-distance telephone company charges its customers by the following r ...
- PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)
题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...
- 【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)
题意: 输入一个正整数N(N<=100),表示接下来有N组数据.每组数据先输入一个正整数M(M<=300),表示有300名考生,接下来M行每行输入一个考生的ID和分数,ID由13位整数组成 ...
- PAT (Advanced Level) Practice 1055 The World's Richest (25 分) (结构体排序)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)
题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...
- PAT乙级:1090危险品装箱(25分)
PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清 ...
随机推荐
- regular.js
//手机号验证 var regMobile=/^1[3,5,8]\d{9}$/; //固定电话 var regPhone=/^(^0\d{2}-?\d{8}$)|(^0\d{3}-?\d{7}$)|( ...
- node通过QQ邮箱发送邮件
在nodejs里面使用插件,不多说,首先下载: npm install emailjs 下载好之后,先别急着写代码,应该先设置一下,我这里用QQ邮箱举例子. 首先登陆QQ邮箱,然后点击:设置-> ...
- 本地存储之sessionStorage
源码可以到GitHub上下载! sessionStorage: 关闭浏览器再打开将不保存数据 复制标签页会连同sessionStorage数据一同复制 复制链接地址打开网页不会复制seession ...
- svn和ftp的不同应用场合
作者:朱金灿 来源:http://blog.csdn.net/clever101 本来二者不是同一类的东西,是不能比较.引发我思考的是部门一些同事错把svn工具作为一个文件共享工具.因此我在思考一个问 ...
- JMeter JMeter自身运行性能优化
JMeter自身运行性能优化 by:授客 QQ:1033553122 测试环境 apache-jmeter-2.13 1. 问题描述 单台机器的下JMeter启动较大线程数时可能会出现运行 ...
- Universal-ImageLoader,Picasso,Fresco,Glide对比
Universal-ImageLoader:(估计由于HttpClient被Google放弃,作者就放弃维护这个框架)优点:1.支持下载进度监听2.可以在 View 滚动中暂停图片加载,通过 Paus ...
- CentOS7的/tmp目录自动清理规则
CentOS6以下系统(含)使用watchtmp + cron来实现定时清理临时文件的效果,这点在CentOS7发生了变化. 在CentOS7下,系统使用systemd管理易变与临时文件,与之相关的系 ...
- JavaScript大杂烩13 - 总结ECMAScript 5新功能
虽说这个标准已经出来很久了,所有的主流浏览器的最新版本也都支持了这些特性,但是很多的教程中并没有包含这个部分,这一节我们专门来总结一下这个标准中的新功能. Object的新方法 在最新的JavaScr ...
- mysql8 :客户端连接caching-sha2-password问题
在安装mysql8的时候如果选择了密码加密,之后用客户端连接比如navicate,会提示客户端连接caching-sha2-password,是由于客户端不支持这种插件,可以通过如下方式进行修改: # ...
- Xamarin入门,开发一个简单的练手APP
之前周末用Xamarin练手做了个简单APP,没有啥逻辑基本就是个界面架子,MVVM的简单使用,还有Binding,Command的简单使用,还有一个稍微复杂点两个界面交互处理(子页面新增后关闭,父页 ...