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<<‘\n‘;
    //计算得分;
    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<<‘\n‘;

    }
    return 0;
}

wrong

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

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

原文地址:https://www.cnblogs.com/BlueBlueSea/p/9847857.html

时间: 2024-08-30 14:52:03

1141 PAT Ranking of Institutions[难]的相关文章

1141 PAT Ranking of Institutions PAT甲级

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

1025. PAT Ranking

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneous

pat1025. PAT Ranking (25)

1025. PAT Ranking (25) 时间限制 200 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneous

1025 PAT Ranking[排序][一般]

1025 PAT Ranking (25)(25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediat

1025 PAT Ranking (25 分)

1025 PAT Ranking (25 分) Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately

1025 PAT Ranking (25分)

1025 PAT Ranking (25分) 1. 题目 2. 思路 设置结构体, 先对每一个local排序,再整合后排序 3. 注意点 整体排序时注意如果分数相同的情况下还要按照编号排序 4. 代码 #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> using namespace std; struct stu{ int location_number; char

1025. PAT Ranking (25)

题目如下: Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. No

1025 PAT Ranking (25)(25 point(s))

problem Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test.

PAT 1103 Integer Factorization[难]

1103 Integer Factorization(30 分) The K?P factorization of a positive integer N is to write N as the sum of the P-th power of K positive integers. You are supposed to write a program to find the K?P factorization of N for any positive integers N, K an