zoukankan      html  css  js  c++  java
  • PAT (Advanced Level) Practice 1141 PAT Ranking of Institutions (25分)

    1.题目

    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

    2.代码

    #include<iostream>
    #include<string>
    #include<cstring>
    #include<set>
    #include<map>
    #include<algorithm>
    using namespace std;
    struct node
    {
    	double b=0;
    	double a=0;
    	double t=0;
    	int finals;
    	string name;
    	int count=0;
    };
    struct cmp {
    	bool operator()(const node&x, const node &y)
    	{
    		if (x.finals==y.finals)
    		{
    			if (x.count == y.count)return x.name < y.name;
    			return x.count < y.count;
    		}
    		else return x.finals>y.finals;
    	}
    };
    int main()
    {
    	int n;
    	cin >> n;
    	string temp, oriname;
    	int score;
    	map<string, node>list;
    	set<node, cmp>out;
    	for (int i = 0; i < n; i++)
    	{
    		cin >> temp >> score >> oriname;
    		for (int j = 0; j < oriname.length(); j++)
    		{
    			if (isupper(oriname[j]))oriname[j] = tolower(oriname[j]);
    		}
    		if (temp[0] == 'B') { list[oriname].b += score;	list[oriname].count++;}
    		else if (temp[0] == 'A') { list[oriname].a += score;list[oriname].count++; }
    		else if (temp[0] == 'T') { list[oriname].t += score;list[oriname].count++; }
    	
    	}
    	map<string, node>::iterator it;
    	for (it = list.begin(); it != list.end(); it++)
    	{
    		it->second.name = it->first;
    		it->second.finals = int(it->second.b / 1.5 + it->second.a + it->second.t*1.5);
    		out.insert(it->second);
    	}
    	cout << out.size() << endl;
    	int rank=1,same=0;
    	set<node, cmp>::iterator it2,it3;
    	it3 = out.begin();
    	cout << 1 << ' ' << it3->name << ' ' << it3->finals << ' ' << it3->count << endl;
    	if (out.size() == 1)return 0;
    	it3++;
    	for (it2 = out.begin(); it3 != out.end(); it2++,it3++)
    	{
    		if (it2->finals != it3->finals) { rank += same + 1; same = 0; }
    		if (it2->finals == it3->finals)same++;
    		cout << rank << ' ' << it3->name << ' ' << it3->finals << ' ' << it3->count << endl;
    	}
    
    }
    
    
    
    
    
    
  • 相关阅读:
    利用cubieboard设置samba打印服务器
    CubieTruck上安装mjpg_streamer
    devexpress bandgridview使用总结(14.2)
    WeedFS0.6.8-引用库列表
    NSQ的消息订阅发布测试
    WeedFS问题收集
    WeedFS依赖库 0.6.1
    golang 前置补0
    MsChart<3> 饼状图
    在代码中去掉窗口,全屏显示
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788882.html
Copyright © 2011-2022 走看看