PAT 乙级 1085 PAT单位排行 (25分)

我的个人网站 Cheese的个人主页icon-default.png?t=M4ADhttp://www.cheese.ren/

博客来源 PAT 乙级 1085 PAT单位排行-Cheese的个人博客icon-default.png?t=M4ADhttp://blog.cheese.ren/105

欢迎交换友链 :-)


#include <bits/stdc++.h>

using namespace std;

struct School
{
    double grade=0;
    string name;
    int student_count=0;
    int score=0;
};

bool cmp(const pair<string, School> a, const pair<string, School> b) {
    if (a.second.score != b.second.score) return a.second.score > b.second.score;
    else if (a.second.student_count != b.second.student_count) return a.second.student_count < b.second.student_count;
    else return a.second.name < b.second.name;
}

int main() {
    int n;
    cin >> n;
    map<string, School> schools;
    while (n--) {
        char id[7];
        string school;
        double grade;
        cin >> id >> grade >> school;
        if (id[0] == 'B')
            grade /= 1.5;
        else if (id[0] == 'T')
            grade *= 1.5;
        for (int i=0; i<school.length(); i++)
            if (school[i] >= 'A'  &&  school[i] <= 'Z')
                school[i] += 32;
        schools[school].name = school;
        schools[school].grade += grade;
        schools[school].student_count++;
    }
    for (map<string, School>::iterator i=schools.begin(); i!=schools.end(); i++)
        i->second.score = (int)i->second.grade;
    vector<pair<string, School>> schools_ranking(schools.begin(), schools.end());
    sort(schools_ranking.begin(), schools_ranking.end(), cmp);
    cout << schools_ranking.size() << endl;
    int ranking=1, score_temp=schools_ranking[0].second.score;
    for (int i=0; i<schools_ranking.size(); i++) {
        if (schools_ranking[i].second.score != score_temp) {
            ranking = i + 1;
            score_temp = schools_ranking[i].second.score;
        }
        cout << ranking << " " << schools_ranking[i].second.name << " " << schools_ranking[i].second.score << " " << schools_ranking[i].second.student_count << endl;
    }
    return 0;
}

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值