• 1141 PAT Ranking of Institutions (25分)


    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

    关于PAT的排行,我们要对数据进行输入,求和的时候要注意精度,先累加,再最后求和,然后进行floor()函数一下,是为了舍去小数(这边是最后一个测试点),然后我们即可计算排行。

    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <cmath>
    #include <unordered_map>
    #include <vector>
    #include <algorithm>
    using namespace std;
    struct node{
        int rank, cnt;
        char school[10];
        int score;
        double score_T, score_A, score_B;
        node():score(0), score_T(0), score_A(0), score_B(0), rank(0), cnt(0){}
    };
    unordered_map<string, node*> m;
    vector<node> v;
    bool cmp(node& n1, node& n2) {
        if(n1.score != n2.score) return n1.score > n2.score;
        if(n1.cnt != n2.cnt) return n1.cnt < n2.cnt;
        return strcmp(n1.school, n2.school) < 0;
    }
    int main() {
        char id[10], school[10];
        int N;
        double score;
        scanf("%d", &N);
        while(N--) {
            scanf("%s%lf%s", id, &score, school);
            for(int i = 0; i < strlen(school); i++) 
                school[i] = tolower(school[i]);
            if(m[school] == NULL) {
                m[school] = new node();
                strcpy(m[school]->school, school);
            }
            if(id[0] == 'T') m[school]->score_T += score;
            else if(id[0] == 'A') m[school]->score_A += score;
            else m[school]->score_B += score;
            m[school]->cnt++;
        }
        for(auto x: m) {
            x.second->score = floor(x.second->score_A + x.second->score_B / 1.5 + x.second->score_T * 1.5);
            v.push_back(*x.second);
        }
        sort(v.begin(), v.end(), cmp);
        v[0].rank = 1;
        for(int i = 1; i < v.size(); i++) {
            if((int)v[i].score == (int)v[i - 1].score) 
                v[i].rank = v[i - 1].rank;
            else v[i].rank = i + 1;
        }
        printf("%lu
    ", v.size());
        for(int i = 0; i < v.size(); i++)
            printf("%d %s %d %d
    ", v[i].rank, v[i].school, v[i].score, v[i].cnt);
        return 0;
    }
  • 相关阅读:
    CSS中的伪类与伪元素
    jquery $(document).ready() 与window.onload的区别
    jquery控件的学习
    jQuery之$(document).ready()使用介绍
    html清除浮动的6种方法示例
    CSS 的优先级机制[总结]
    Phpthink入门基础大全(CURD部分)
    2014 年 25 款超棒的免费 Bootstrap 模板
    javascript和jQuery知识点总结
    JavaScript网页特效5则
  • 原文地址:https://www.cnblogs.com/littlepage/p/12818542.html
Copyright © 2020-2023  润新知