1141 PAT Ranking of Institutions (25)

// PATA 20180318 B
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.

code ------------------------------------
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN = 100000;
struct school {
    int Rank;
    char SchoolN[20];
    double TWS;
    int TWSInt;  //注意是按总分的int型来排名!
    int Ns;
} School[MAXN];
map<string,int> mapp;
int index1 = 0;
int findIndex(char SchoolName[20]) {
    if(mapp.find(SchoolName) != mapp.end()) {
        return mapp[SchoolName];
    } else {
        mapp[SchoolName] = index1;  
        return index1++;
    }
}
bool cmp(school a, school b) {
    if(a.TWSInt != b.TWSInt) return a.TWSInt > b.TWSInt;
    if(a.Ns != b.Ns) return a.Ns < b.Ns;
    return strcmp(a.SchoolN,b.SchoolN) < 0;  
}
int main() {
    int N;
    scanf("%d",&N);
    char ID[20];
    double Score;
    char SchoolName[20];
    for(int i=0; i<N; i++) {
        scanf("%s %lf %s",&ID,&Score,&SchoolName);
        for(int j=0; j<strlen(SchoolName); j++)
            if(SchoolName[j] >= 'A' && SchoolName[j] <= 'Z') SchoolName[j] += 32;
        int currentIndex = findIndex(SchoolName);
        strcpy(School[currentIndex].SchoolN,SchoolName);
        if(ID[0] == 'B') School[currentIndex].TWS += Score/1.5;
        if(ID[0] == 'T') School[currentIndex].TWS += Score*1.5;
        if(ID[0] == 'A') School[currentIndex].TWS += Score;
        School[currentIndex].Ns ++;
    }
    for(int i=0; i<index1; i++)
        School[i].TWSInt = (int)School[i].TWS;
    sort(School, School + index1, cmp);
    School[0].Rank = 1;
    for(int i=1; i<index1; i++) {
        if(School[i].TWSInt == School[i-1].TWSInt) School[i].Rank = School[i-1].Rank;
        else School[i].Rank = i+1;
    }
    printf("%d\n",index1);
    for(int i=0; i<index1; i++)
        printf("%d %s %d %d\n",School[i].Rank,School[i].SchoolN,School[i].TWSInt,School[i].Ns);
    return 0;
}


大佬们说这是道水题... QAQ  QAQ  QAQ 

截图:

    

    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值