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. 【Java并发编程】22、Exchanger源码解析(JDK1.7)

    Exchanger是双向的数据传输,2个线程在一个同步点,交换数据.先到的线程会等待第二个线程执行exchangeSynchronousQueue,是2个线程之间单向的数据传输,一个put,一个tak ...

  2. 【Java深入研究】8、Java中Unsafe类详解

    java不能直接访问操作系统底层,而是通过本地方法来访问.Unsafe类提供了硬件级别的原子操作,主要提供了以下功能: 1.通过Unsafe类可以分配内存,可以释放内存: 类中提供的3个本地方法all ...

  3. 封装方法公共文件common.js

    /** * Created by Administrator on 2017/3/24. */ /** * 格式化日期 * @param dt 日期对象 * @returns {string} 返回值 ...

  4. c++中的this指针和c#中的this引用

    先总结一下: 在c++中this为指针,使用"->"操作符来获取当前实例中的成员 在c#中this为引用,使用"."操作符来获取当前实例中的成员 下面内容 ...

  5. CSS3景深-perspective

    3D视图正方体: <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  6. input上传文件个数控制

    HTML: <h3>请上传[2,5]个文件</h3> <form action="" enctype="multipart/form-dat ...

  7. 从零开始学习html(一) Html介绍

    我是初学者,这个是我学习的过程,当做笔记记录下来,如有错误希望高手指正. 原地址 一.代码初体验,制作我的第一个网页 <!DOCTYPE HTML> <html> <he ...

  8. loadrunner 脚本开发-字符串编码转换

    字符串编码转换 by:授客 QQ:1033553122   相关函数 lr_convert_string_encoding函数 功能:字符串编码转换 原型: int lr_convert_string ...

  9. 《Inside C#》笔记(九) 表达式和运算符

    赋值和比较操作是一门语言最基本的功能. 一 基本概念 a)基本的运算符有加.减.乘.除.取余.赋值. 运算结果需要保存在内存的某个区域,有时直接保存在操作数本身,不管怎样,如果没有保存运算结果,编译器 ...

  10. 关于string指针

    string str("hello world"); string *pstr = &str; cout << pstr[0] << endl; c ...