1141 PAT Ranking of Institutions (25分)

本文介绍了一个基于学生表现的教育机构排名系统的实现方法。系统接收测试考生的信息,包括ID、分数和所属学校,然后根据特定的评分规则计算各学校的总加权分数(TWS),并按TWS进行排名。在TWS相同的情况下,按考生数量和学校代码字母顺序作为次级排序标准。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

注意点:

使用map可能超时
score是取整数部分,而不是四舍五入

#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<string>
#include<vector>
using namespace std;
struct ins{
	string school;
	float score = 0;
	int num = 0;
};
unordered_map<string, ins>rec;
int n;
bool cmp(ins s1, ins s2) {
	int i1 = s1.score, i2 = s2.score;
	if (i1 != i2)return i1 > i2;
	if (s1.num != s2.num)return s1.num < s2.num;
	else
		return s1.school < s2.school;
}
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		string id, sch;
		float score;
		cin >> id >> score >> sch;
		transform(sch.begin(), sch.end(), sch.begin(), ::tolower);
		if (id[0] == 'B')score /= 1.5;
		else if (id[0] == 'T')score *= 1.5;
		rec[sch].school = sch;
		rec[sch].num++;
		rec[sch].score += score;
	}
	vector<ins>temp;
	for (auto it = rec.begin(); it != rec.end(); it++)temp.push_back(it->second);
	sort(temp.begin(), temp.end(), cmp);
	int ts0 = temp[0].score, rank = 1;
	cout << temp.size() << endl;
	for (int i = 0; i < temp.size(); i++) {
		int tsi = temp[i].score;
		if (tsi != ts0) {
			rank = i + 1;
			ts0 = tsi;
		}
		cout << rank << " " << temp[i].school << " " << tsi << " " << temp[i].num << endl;
	}
	return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值