【PAT】A1141 PAT Ranking of Institutions (25point(s))


Author: CHEN, Yue
Organization: 浙江大学
Time Limit: 800 ms
Memory Limit: 64 MB
Code Size Limit: 16 KB

A1141 PAT Ranking of Institutions (25point(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.

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

Code

#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <unordered_map>
using namespace std;
struct NODE{
    int cnt,tws;
    string name;
};
unordered_map<string,int> stuCnt;
unordered_map<string,double> tws;
vector<NODE> school;
bool cmp(NODE a, NODE b){
    if(a.tws!=b.tws)  return a.tws>b.tws;
    else if(a.cnt!=b.cnt)   return a.cnt<b.cnt;
    else    return a.name<b.name;
}
int main(){
    int n,ranks=1,same=1;
    double b;
    string a,c;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a>>b>>c;
        for(int j=0;j<c.size();j++){
            if(c[j]>='A'&&c[j]<='Z')
                c[j]=c[j]+32;
        }
        if(a[0]=='A')   tws[c]+=b;
        else if(a[0]=='B')  tws[c]+=b/1.5;
        else    tws[c]+=b*1.5;
        stuCnt[c]++;
    }
    for(unordered_map<string,int>::iterator it=stuCnt.begin();it!=stuCnt.end();it++){
        NODE temp;
        temp.name=it->first;
        temp.cnt=stuCnt[it->first];
        temp.tws=(int)tws[it->first];
        school.push_back(temp);
    }
    sort(school.begin(),school.end(),cmp);
    printf("%d\n",school.size());
    for(int i=0;i<school.size();i++){
        if(i!=0&&(school[i].tws!=school[i-1].tws))  ranks=i+1;
        printf("%d %s %d %d\n",ranks,school[i].name.c_str(),school[i].tws,school[i].cnt);
    }
    return 0;
}

Analysis

-已知每个学生的id、分数、学校名。

-输出学校总数,并且根据学校的TWS(加权平均TWS=ScoreB/1.5 + ScoreA + ScoreT*1.5,T、A、B分别表示考顶甲乙的成绩)增序输出。输出内容为:学校排名、学校名称、TWS、学校参赛人数。

-注意:学校名称不区分大小写,且输出时候以小写方式输出。不同学校有相同的TWS时按照参赛学生人数增序排列,如果还有相同,则按照学校名字母增序排列。

发布了159 篇原创文章 · 获赞 17 · 访问量 1万+

猜你喜欢

转载自blog.csdn.net/ztmajor/article/details/104079412