1141 PAT Ranking of Institutions (25 point(s))

思路:

c++/STL,利用map保存输入,然后计算ScoreX,然后输出到vector,最后sort排序,输出排序结果。

1141 PAT Ranking of Institutions (25 point(s))

After each PAT, the PAT Center will announce the ranking of institutions based on their students' performances. Now you are asked to generate the ranklist.

Input Specification:

Each input file contains one test case. For each case, the first line gives a positive integer N (≤10​5​​), which is the number of testees. Then N lines follow, each gives the information of a testee in the following format:

ID Score School

where ID is a string of 6 characters with the first one representing the test level: B stands for the basic level, A the advanced level and T the top level; Score is an integer in [0, 100]; and School is the institution code which is a string of no more than 6 English letters (case insensitive). Note: it is guaranteed that ID is unique for each testee.

Output Specification:

For each case, first print in a line the total number of institutions. Then output the ranklist of institutions in nondecreasing order of their ranks in the following format:

Rank School TWS Ns

where Rank is the rank (start from 1) of the institution; School is the institution code (all in lower case); ; TWS is the total weighted score which is defined to be the integer part of ScoreB/1.5 + ScoreA + ScoreT*1.5, where ScoreX is the total score of the testees belong to this institution on level X; and Ns is the total number of testees who belong to this institution.

The institutions are ranked according to their TWS. If there is a tie, the institutions are supposed to have the same rank, and they shall be printed in ascending order of Ns. If there is still a tie, they shall be printed in alphabetical order of their codes.

Example:

#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<cstring>
using namespace std;

struct Score {
    string School;
    int A;
    int B;
    int T;
    int Total;
    int Cnt;
    bool operator <(const Score& other) const {
        return Total==other.Total?(Cnt==other.Cnt?(School<other.School):Cnt<other.Cnt):(Total>other.Total);
    }
};

int main()
{
    int N;
    cin >> N;
    map<string, Score> index;
    for(int i = 0; i < N; i++) {
        string ID, school;
        int score;
        cin >> ID >> score >> school;
        transform(school.begin(), school.end(), school.begin(), ::tolower);
        index[school].Cnt++;
        index[school].School = school;
        if(ID[0] == 'A') index[school].A += score;
        else if(ID[0] == 'B') index[school].B += score;
        else if(ID[0] == 'T') index[school].T += score;
    }
    vector<Score> S;
    for(auto x = index.begin(); x != index.end(); x++) {
        x->second.Total = x->second.B/1.5 + x->second.A + x->second.T*1.5;
        S.push_back(x->second);
    }
    sort(S.begin(), S.end());
    int last = 0;
    int rank = 1;
    int size = S.size();
    cout << size << endl;
    for(int i = 0; i < size; i++) {
        if(S[i].Total != last) {
            rank = i + 1;
            last = S[i].Total;
        }
        printf("%d %s %d %d\n", rank, S[i].School.c_str(), S[i].Total, S[i].Cnt);
    }
}

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值