1140 Look-and-say Sequence

#include<iostream>

#include<map>

#include<vector>

#include<algorithm>

using namespace std;

class Record{

public:

string school;

double scores;

int num;

// int rank;

bool operator < (Record const a){

if(scores==a.scores)

{

if(num==a.num)return school<a.school;

else return num<a.num;

}

else return scores>a.scores;

}

};

 

string func(string str)

{

for(int i=0;i<str.size();++i)

{

if(str[i]>='A'&&str[i]<='Z') str[i]=str[i]-'A'+'a';

}

return str;

}

 

int main()

{

map<string,int> schoolhash;

vector<Record> records;

int n;

int k=0;

cin>>n;

for(int i=0;i<n;++i)

{

string ID,school;

int score;

cin>>ID>>score>>school;

school = func(school);

map<string,int>::iterator it = schoolhash.find(school);

if(it==schoolhash.end())

{

schoolhash[school] = k++;

Record tmp;

tmp.school = school;

double w = 1;

if(ID[0]=='B') w = 1/1.5;

if(ID[0]=='T') w = 1.5;

tmp.scores = score*w;

tmp.num = 1;

records.push_back(tmp);

}

else

{

int t = schoolhash[school];

records[t].num++;

double w = 1;

if(ID[0]=='B') w = 1/1.5;

if(ID[0]=='T') w = 1.5;

records[t].scores+=score*w;

}

}

for(int i=0;i<records.size();++i)

{

records[i].scores = int(records[i].scores);

}

sort(records.begin(),records.end());

int rank=1;

cout<<records.size()<<endl;

while(rank<=records.size())

{

int i = rank;

cout<<rank<<" "<<records[i-1].school<<" "<<records[i-1].scores<<" "<<records[i-1].num<<endl;

while(i<records.size()&&records[i-1].scores==records[i].scores) {

cout<<rank<<" "<<records[i].school<<" "<<records[i].scores<<" "<<records[i].num<<endl;

++i;

}

rank=i+1;

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值