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;
    	}
    
    }
    
    
    
    
    
    
  • 相关阅读:
    Changing Icon File Of Push Button At Runtime In Oracle Forms 6i
    Set Font Properties On Mouse Hover Of Push Button And Text Items At Run time In Oracle Forms
    Change An Item Property Using Set_Item_Property In Oracle Forms
    Calling / Running a report in Oracle forms 10g / 11g
    Change Or Set Report Object Property At Run Time In Oracle Forms Using Set_Report_Object_Property Command
    Refresh / Updating a form screen in Oracle D2k Forms 6i
    Know How And When To Use System.Message_Level To Control Messages In Oracle Forms
    Perform Cut Copy Paste Operations Using Cut_Region Copy_Region Paste_Region Commands In Oracle Forms
    CHECKBOX_CHECKED built-in in Oracle D2k Forms
    Limiting To Select Only 5 Check Boxes Out Of Ten In Oracle Forms
  • 原文地址:https://www.cnblogs.com/Jason66661010/p/12788882.html
Copyright © 2011-2022 走看看