zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    trailRenderer
    通过sysobjects快速查找SQLServer中是否有某个表、视图、存储过程等对象实操
    浅谈信息系统(IT)项目管理-序幕
    使用open xml 判断sharepoint文档是否损坏
    Sharepoint the file is locked for use domainuser edit.文件被锁定,解锁方式
    sharepoint 列表库指定序号规则
    Biztalk 宏
    Biztalk 在流程中定义将消息保存为文件的文件名
    Biztalk 2013 新特性简介(英)
    devexpress gridview,selectedrowchanged
  • 原文地址:https://www.cnblogs.com/littlepage/p/12818542.html
Copyright © 2011-2022 走看看