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 (≤10​5​​), 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 分)——排序,结构体初始化的更多相关文章

  1. PAT A1075 PAT Judge (25 分)——结构体初始化,排序

    The ranklist of PAT is generated from the status list, which shows the scores of the submissions. Th ...

  2. PAT 甲级 1012 The Best Rank (25 分)(结构体排序)

    题意: 为了评估我们第一年的CS专业学生的表现,我们只考虑他们的三个课程的成绩:C - C编程语言,M - 数学(微积分或线性代数)和E - 英语.同时,我们鼓励学生强调自己的最优秀队伍 - 也就是说 ...

  3. 【PAT甲级】1016 Phone Bills (25 分)(结构体排序)

    题意: 输入24个正整数代表从0到23每个小时通话一分钟花费的美分.输入一个正整数N(<=1000),然后输入N组字符串,每个字符串包含客户的名字和通话的时刻以及打出或者挂断的状态. 按照字典序 ...

  4. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  5. PAT 甲级 1016 Phone Bills (25 分) (结构体排序,模拟题,巧妙算时间,坑点太多,debug了好久)

    1016 Phone Bills (25 分)   A long-distance telephone company charges its customers by the following r ...

  6. PAT 甲级1025 PAT Ranking (25 分)(结构体排序,第一次超时了,一次sort即可小技巧优化)

    题意: 给定一次PAT测试的成绩,要求输出考生的编号,总排名,考场编号以及考场排名. 分析: 题意很简单嘛,一开始上来就,一组组输入,一组组排序并记录组内排名,然后再来个总排序并算总排名,结果发现最后 ...

  7. 【PAT甲级】1025 PAT Ranking (25 分)(结构体排序,MAP<string,int>映射)

    题意: 输入一个正整数N(N<=100),表示接下来有N组数据.每组数据先输入一个正整数M(M<=300),表示有300名考生,接下来M行每行输入一个考生的ID和分数,ID由13位整数组成 ...

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

  9. 【PAT甲级】1026 Table Tennis (30 分)(结构体排序,trick较多)

    题意: 输入一个正整数N(<=10000),表示客户(对)的大小,接着输入N行数据,每行包括一对顾客到场的时间,想要玩的时间,以及是否是VIP客户.接下来输入两个正整数K,M(K<=100 ...

  10. PAT乙级:1090危险品装箱(25分)

    PAT乙级:1090危险品装箱(25分) 题干 集装箱运输货物时,我们必须特别小心,不能把不相容的货物装在一只箱子里.比如氧化剂绝对不能跟易燃液体同箱,否则很容易造成爆炸. 本题给定一张不相容物品的清 ...

随机推荐

  1. Matlab diag的用法

    X = diag(v,k) 以向量v的元素作为矩阵X的第k条对角线元素,当k=0时,v为X的主对角线:当k>0时,v为上方第k条对角线 几个例子: 当k> v=[1 2 3]; >& ...

  2. IronPython初体验

    介绍 在 C# 程序中嵌入 IronPython 得到了很好的支持.在本教程中,我们将展示如何完成这个项目. 首先,我们将展示两个非常基本的例子,说明如何执行一个不导入任何模块的非常简单的脚本.然后, ...

  3. 使用iconv进行编码gb2312转utf8 转码失败的坑

    iconv 编码gb2312转utf8 转码失败的坑 使用背景 项目中使用thrift进行C#程序调用c++接口,其中的协议是通过json进行传输的,由于默认thrift使用utf8进行传输,而C#和 ...

  4. HDU5543(SummerTrainingDay03-O DP)

    Pick The Sticks Time Limit: 15000/10000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others ...

  5. csharp: using HtmlAgilityPack and ScrapySharp reading Url find text

    https://github.com/exaphaser/ScrapySharp https://github.com/zzzprojects/html-agility-pack https://gi ...

  6. Excel破解工作表保护

    宏运行 Public Sub Password_cracking() Const DBLSPACE As String = vbNewLine & vbNewLine Const AUTHOR ...

  7. http-server服务跨域设置

    http-server --cors -p 9999 ------------------------------------------------------------------------- ...

  8. Android项目实战(三十二):圆角对话框Dialog

    前言: 项目中多处用到对话框,用系统对话框太难看,就自己写一个自定义对话框. 对话框包括:1.圆角 2.app图标 , 提示文本,关闭对话框的"确定"按钮 难点:1.对话框边框圆角 ...

  9. 【redis专题(1)】安装与启动

    简介 REmote DIctionary Server(Redis) 是一个由Salvatore Sanfilippo(redis之父)写的key-value存储系统. Redis提供了一些丰富的数据 ...

  10. 06-OpenLDAP密码策略

    阅读视图 openldap密码策略 OpenLDAP服务端定制密码策略 客户端策划策略实例 定义用户第一次登录就修改密码 问题排查手册 重点推荐官方文档 备注:本文依然承接系列文. 1. openld ...