1141 PAT Ranking of Institutions (25分)

 

#include<map>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;

struct schoolType {
    string name;
    int sb, sa, st;
    int ns, tws;
};

bool com(schoolType a, schoolType b) {
    if (a.tws > b.tws) return true;
    else if (a.tws < b.tws) return false;
    else if (a.ns < b.ns) return true;
    else if (a.ns > b.ns) return false;
    else return a.name < b.name;
}

string trueschool(string s) {
    for (int i = 0; i < s.size(); i++) {
        if (s[i] >= 'A' && s[i] <= 'Z') {
            s[i] = s[i] - 'A' + 'a';
        }
    }
    return s;
}

int main() {
    int n;
    cin >> n;
    string id, school;
    map<string, int> mp;
    int score;
    int i = 0;
    vector<schoolType> sl;    // school list
    map<string, int>::iterator it;
    if (n == 0) {
        cout << 0 << endl;
        return 0;
    }
    while(n--) {
        cin >> id >> score >> school;
        school = trueschool(school);
        it = mp.find(school);
        if (it == mp.end()) {
            mp[school] = i;
            schoolType schooltemp;
            schooltemp.sb = schooltemp.sa = schooltemp.st = schooltemp.ns = 0;
            schooltemp.name = school;
            sl.push_back(schooltemp);
            i++;
        }
        int t = mp[school];
        sl[t].ns++;
        if (id[0] == 'B') sl[t].sb += score;
        else if (id[0] == 'A') sl[t].sa += score;
        else sl[t].st += score;
    }
    for (int j = 0; j < i; j++) {
        double d = sl[j].sb / 1.5 + sl[j].sa + sl[j].st * 1.5;
        sl[j].tws = d;
    }
    sort(sl.begin(), sl.end(), com);
    int r = 1;  // the rank of the last school
    score = -1;  // the tws of the last school
    cout << mp.size() << endl;
    cout << r << ' ' << sl[0].name << ' ' << sl[0].tws << ' ' << sl[0].ns << endl;
    for (int j = 1; j < i; j++) {
        if (sl[j].tws != sl[j - 1].tws) r = j + 1;
        cout << r << ' ' << sl[j].name << ' ' << sl[j].tws << ' ' << sl[j].ns << endl;
    }

    return 0;
}

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值