PAT (Basic Level) Practice (Chinese) 1085 PAT unit ranking (25 points) (map search + set sorting + parallel ranking)

1. topic

After each PAT test, the test center will release a list of candidates. This question asks you to realize this function.

Input format:

Enter the first line to give a positive integer N (≤ 10 5), that is, the number of candidates. Then line N, each line gives a candidate's information in the following format:

Admission No. scoring school

Among them, the examination permit number is A string of six characters, with the initial letter indicating the level of the examination: B represents level B, A represents level A, T represents the top level; the score is an integer within the [0, 100] range; the school is A unit code composed of no more than six English letters (regardless of case). Note: the questions ensure that each candidate's admission number is different.

Output format:

First output the number of units in a row. Then output the leaderboards of units in non descending order in the following format:

Number of candidates with weighted total score

The ranking is the ranking of the unit (starting from 1); the school is the unit code output in lowercase letters; the weighted total score is defined as the integral part of class B total score / 1.5 + class a total score + top level total score * 1.5; the number of candidates is the total number of candidates belonging to the unit.

Schools are first ranked on a weighted total score. If there is a parallel, it should correspond to the same ranking, and output according to the number of candidates in ascending order. If it is still in parallel, it will be output in the dictionary order of unit code.

Input example:

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

Output example:

5
1 cmu 192 2
1 au 192 3
3 pku 100 1
4 hypu 81 2
4 lanx 81 2

2. Topic analysis

1. The set is a constant pointer, and the content cannot be modified (it2 - > final = 2). No way

2. Pay attention to the parallel ranking 11. The end is 3

3. code

#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;
	}

}

 

139 original articles published, praised 4, visited 2498
Private letter follow

Posted on Sun, 08 Mar 2020 09:27:42 -0400 by Naez