1141 PAT Ranking of Institutions[难]

Posted bluebluesea

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1141 PAT Ranking of Institutions[难]相关的知识,希望对你有一定的参考价值。

 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 (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, Athe 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

 题目大意:给出学生的id、分数、学校了,然后计算学校的相关排名,通过计算本考场内考生的等级分数,等最后按照一个规则排名。

 //这个题确实挺麻烦的。

技术分享图片
#include <iostream>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
struct Sch{
    int sb,sa,st;
    int fin,stu;
    string name;
    Sch(string n){
        name=n;
        sb=0;sa=0;st=0;stu=1;}
    void cal(){//但是如何取整数部分呢?如果直接赋值那应该是4舍5入的。
        fin=sb/1.5+sa+st*1.5;
    }
};

string lower(string s){
    for(int i=0;i<s.size();i++){
        if(s[i]>=A&&s[i]<=Z){
            s[i]=s[i]-A+a;
        }
    }
    return s;
}

map<string,int> name2id;
vector<Sch> vsch;

void add(string id,int index,int score){
    if(id[0]==A)
        vsch[index].sa+=score;
    else if(id[0]==B)
        vsch[index].sb+=score;
    else vsch[index].st+=score;
}

bool cmp(Sch& a,Sch& b){//排序函数。
    if(a.fin>b.fin)return true;
    else if(a.fin==b.fin&&a.stu<b.stu)return true;
    else if(a.fin==b.fin&&a.stu==b.stu&&a.name<b.name)return true;
}

int main() {
    int n;
    cin>>n;
    string id,sh;
    int sco,ct=0;//ct表示有多少个学校。
    for(int i=0;i<n;i++){
        cin>>id>>sco>>sh;
        sh=lower(sh);//函数是如何转换大小写?
        if(name2id.count(sh)==0){//如果当前机构不存在的话
            name2id[sh]=ct++;
            vsch.push_back(Sch(sh));//把机构的名字传进去。
            add(id,ct-1,sco);
        }else{//如果已经存在
            int temp=name2id[sh];
            add(id,temp,sco);
            vsch[temp].stu++;//又多了一个学生。
        }
    }
    int size=name2id.size();
    cout<<size<<
;
    //计算得分;
    for(int i=0;i<vsch.size();i++){
        vsch[i].cal();
    }
    sort(vsch.begin(),vsch.end(),cmp);
    int rank=1;
    for(int i=0;i<size;i++){
        if(i!=0){
            if(vsch[i].fin!=vsch[i-1].fin)
                rank++;//这时候排名才++;
            //其他情况排名不++
        }
        cout<<rank<<" "<<vsch[i].name<<" "<<vsch[i].fin<<" "<<vsch[i].stu<<
;

    }
    return 0;
}
wrong

 

//这个我写了将近一个小时,但是最终第一次提交结果如下: 

技术分享图片

 真是心里凉凉,待会再看柳神的吧。

以上是关于1141 PAT Ranking of Institutions[难]的主要内容,如果未能解决你的问题,请参考以下文章

1141 PAT Ranking of Institutions (25)

PAT甲级1141PAT Ranking of Institutions

A 1141 PAT Ranking of Institutions (25分)

1141 PAT Ranking of Institutions (25 分)难度: 一般 / 知识点: 排序

PAT甲级——A1025 PAT Ranking

PAT A1025 PAT Ranking(25)