1141. PAT Ranking of Institutions (25) 22‘

#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
struct node{
    string id;
    int score;
    string school;
};
struct Node{
    int rank;
    string school;
    int score;
    int ns;
};
int get_score(char c, int s){
    if(c == 'B') return s / 1.5;
    if(c == 'A') return s;
    else return s * 1.5;
}
bool cmp(Node &a, Node &b){
    if(a.score == b.score){
        if(a.ns == b.ns){
            return a.school < b.school;
        }else{
            return a.ns < b.ns;
        }
    }else{
        return a.score > b.score;
    }

}

int main( )
{
    int n;
    cin >> n;
    vector<node> stu;
    map<string, int> ma;
    int cnt = 0;
    for(int i = 0; i < n; i++){
        node t;
        cin >> t.id >> t.score >> t.school;
        for(int j = 0; j < t.school.length(); j++){
            if(t.school[j] >= 'A' && t.school[j] <= 'Z')  t.school[j] = t.school[j] + 'a' - 'A';
        }
        t.score = get_score(t.id[0], t.score);
        stu.push_back(t);
        if(!ma[t.school]){
            ma[t.school] = cnt + 1;
            cnt++;
        }
    }

    map<string, bool> mb;
    vector<Node> v(cnt);
    for(int i = 0; i < stu.size(); i++){
        string t = stu[i].school;
        int j = ma[t] - 1;
        if(!mb[t]){
            v[j].school = stu[i].school;
            v[j].score = 0;
            v[j].ns = 0;
            mb[t] = true;
        }
        v[j].score += stu[i].score;
        v[j].ns++;
    }
    sort(v.begin(), v.end(), cmp);
    cout << cnt << endl;
    int rank = 1;
    for(int i = 0; i < cnt; i++){
        int t = 0;
        printf("%d %s %d %d\n", rank, v[i].school.c_str(), v[i].score, v[i].ns);
        t++;
        while(i+1 < cnt && v[i+1].score == v[i].score){
            printf("%d %s %d %d\n", rank, v[i+1].school.c_str(), v[i+1].score, v[i+1].ns);
            i++;
            t++;
        }
        rank += t;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_31474267/article/details/79604506