1141 PAT Ranking of Institutions(25 分)

#include
#include
#include
#include
#include
using namespace std;
const int maxn = 1e5 + 10;
struct node {
    string codes;
    int A, B, T, tws, ns, rank;
    bool operator<(const node&x)const
    {
        return tws == x.tws ? ns == x.ns ? codes < x.codes : ns x.tws;
    }
}school[maxn];
mapmp, stu;
int n, cnt;
string Lower(string s)
{
    for (int i = 0; i < s.length(); i++)
    {
        if (s[i] >= 'A'&&s[i] <= 'Z')s[i] += 32;
    }
    return s;
}
int main()
{
    scanf("%d", &n);
    getchar();
    while (n--)
    {
        string id, sch;
        int score;
        cin >> id >> score >> sch;
        sch = Lower(sch);
        if (mp.find(sch) == mp.end())mp[sch] = cnt, cnt++, school[mp[sch]].codes = sch;
        if (id[0] == 'A')school[mp[sch]].A += score;
        else if (id[0] == 'B')school[mp[sch]].B += score;
        else if (id[0] == 'T')school[mp[sch]].T += score;
        school[mp[sch]].ns++;
    }
    for (int i = 0; i < cnt; i++)
    {
        school[i].tws = school[i].B / 1.5 + school[i].A + school[i].T*1.5;
    }
    sort(school, school + cnt);
    printf("%d\n", cnt);
    school[0].rank = 1;
    for (int i = 1; i < cnt; i++)
    {
        if (school[i].tws == school[i-1].tws)school[i].rank = school[i - 1].rank;
        else school[i].rank = i + 1;
    }
    for (int i = 0; i < cnt; i++)
    {
        cout << school[i].rank << " " << school[i].codes << " " << school[i].tws << " " << school[i].ns << endl;
    }
    return 0;
}

你可能感兴趣的:(1141 PAT Ranking of Institutions(25 分))