zoukankan      html  css  js  c++  java
  • A1141. PAT Ranking of Institutions

    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 (≤), 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.

    Sample Input:

    10
    A57908 85 Au
    B57908 54 LanX
    A37487 60 au
    T28374 67 CMU
    T32486 24 hypu
    A66734 92 cmu
    B76378 71 AU
    A47780 45 lanx
    A72809 100 pku
    A03274 45 hypu
    

    Sample Output:

    5
    1 cmu 192 2
    1 au 192 3
    3 pku 100 1
    4 hypu 81 2
    4 lanx 81 2


    #include<iostream>
    #include<cstdio>
    #include<string>
    #include<map>
    #include<algorithm>
    using namespace std;
    typedef struct NODE{
        string scId;
        int Asum, Bsum, Tsum, TWS;
        int stuNum, rank;
        NODE(){
            Asum = 0; Bsum = 0; Tsum = 0; stuNum = 0;
            TWS = 0;
        }
    }info;
    bool cmp(info a, info b){
        if(a.TWS != b.TWS){
            return a.TWS > b.TWS;
        }else{
            if(a.stuNum != b.stuNum)
                return a.stuNum < b.stuNum;
            else return a.scId < b.scId;
        }
    }
    info school[100010];
    map<string, int>mp;
    int pt = 0;
    void str2Low(string &ss){
        for(int i = 0; i < ss.length(); i++){
            if(ss[i] >= 'A' && ss[i] <= 'Z'){
                ss[i] = ss[i] - 'A' + 'a';
            }
        }
    }
    int main(){
        int N;
        scanf("%d", &N);
        for(int i = 0; i < N; i++){
            string id, sch;
            int point;
            cin >> id >> point >> sch;
            str2Low(sch);
            int index;
            if(mp.count(sch) == 0){
                mp[sch] = pt++;
                index = pt - 1;
                school[index].scId = sch;
            }else{
                index = mp[sch];
            }
            if(id[0] == 'A'){
                school[index].Asum += point;
            }else if(id[0] == 'B'){
                school[index].Bsum += point;
            }else{
                school[index].Tsum += point;
            }
            school[index].stuNum++;
        }
        for(int i = 0; i < pt; i++){
            school[i].TWS = (double)school[i].Bsum / 1.5 + (double)school[i].Asum + (double)school[i].Tsum * 1.5;
        }
        sort(school, school + pt, cmp);
        school[0].rank = 1;
        cout << pt << endl;
        for(int i = 1; i < pt; 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 < pt; i++){
            cout << school[i].rank << " " << school[i].scId << " " << school[i].TWS << " "<<school[i].stuNum << endl;
        }
        cin >> N;
        return 0;
    }
    View Code
  • 相关阅读:
    〖Python〗-- Tornado自定义session组件
    〖Python〗-- Tornado异步非阻塞
    〖Python〗-- Tornado基础
    〖Python〗-- Flask
    〖Python〗-- 设计模式
    〖Python〗-- Celery分布式任务队列
    〖Demo〗-- CosPlayPermission
    05——wepy框架中的一些细节
    04——wepy框架搭建
    03——微信小程序官方demo讲解——page部分
  • 原文地址:https://www.cnblogs.com/zhuqiwei-blog/p/9566623.html
Copyright © 2011-2022 走看看