C/C++教程

PAT (Advanced Level) Practice 1141 PAT Ranking of Institutions (25 分) 凌宸1642

本文主要是介绍PAT (Advanced Level) Practice 1141 PAT Ranking of Institutions (25 分) 凌宸1642,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

PAT (Advanced Level) Practice 1141 PAT Ranking of Institutions (25 分) 凌宸1642

题目描述:

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.

译:每次PAT后,PAT中心会根据学生的表现公布院校排名。 现在要求您生成排名列表。


Input Specification (输入说明):

Each input file contains one test case. For each case, the first line gives a positive integer N(≤105) , 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.

译:每个输入文件包含一个测试用例。 对于每种情况,第一行给出一个正整数 N(≤105),即受试人数。 然后是 N 行,每行给出一个被测者的信息,格式如下:

ID Score School

其中 ID 为6个字符的字符串,第一个代表测试级别:B代表基础级别,A代表高级,T代表顶级; 分数是[0, 100]中的整数; School 是机构代码,是不超过 6 个英文字母的字符串(不区分大小写)。 注意:保证每个被测者的 ID 是唯一的。


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.

译:对于每种情况,首先在一行中打印机构总数。 然后按以下格式输出机构排名表,按排名不降序排列:

Rank School TWS Ns

其中 Rank 是机构的排名(从 1 开始); School 是机构代码(全部小写); TWS 为加权总分,定义为ScoreB/1.5+ScoreA+ScoreT*1.5的整数部分,其中ScoreX为该机构的X级考生总分; Ns 是属于该机构的考生总数。

这些机构根据其 TWS 进行排名。 如果出现平局,则机构应具有相同的等级,并以Ns的升序打印。 如果仍然有平局,则应按其学校编码的字母顺序打印。


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

The Idea:

  • 就是对结构体进行sort排序
  • 有一个坑点,题目中明确说名了,最后的总分时所有等级的总分再进行加权,如果我们按照来一个算一个的话,最后一个测试点时过不了的,一定要先算出所有等级各自的总分,然后进行加权求学校最后的总分。

The Codes:

#include<bits/stdc++.h>
using namespace std ;
const int maxn = 100010 ;
struct Node{
	string name ;
	int gradeA = 0 , gradeB = 0 , gradeT = 0 , score = 0 ;
	int cnt = 0 ; 
}sch[maxn] ;
string id , sname ;
map<string , int > mp ;
int n , score , t , num = 0 ;
bool cmp(Node a , Node b){
	if(a.score != b.score) return a.score > b.score ;
	if(a.cnt != b.cnt) return a.cnt < b.cnt ;
	return a.name < b.name ;
} 
int main(){
	cin >> n ;
	for(int i = 0 ; i < n ; i ++){
		cin >> id >> score >> sname ;
		transform(sname.begin() , sname.end() , sname.begin() , ::tolower) ;
		if(mp.count(sname) == 0) {
			mp[sname] = num  ;
			sch[num ++].name = sname ;
		}
		t = mp[sname] ;
		if(id[0] == 'B') sch[t].gradeB += score ;
		else if(id[0] == 'T') sch[t].gradeT += score  ;
		else sch[t].gradeA += score  ;
		sch[t].cnt ++ ;		
	}
	for(int i = 0 ; i < num ; i ++){
		sch[i].score = sch[i].gradeB * 2.0 / 3 + sch[i].gradeA + sch[i].gradeT *3.0 / 2 ; // 计算每个学校的总分
	}
	sort(sch , sch + num , cmp) ;
	cout << num << endl ;
	int rank = 1 , sc = sch[0].score ;
	for(int i = 0 ; i < num ; i ++){
		if(sch[i].score != sc){
			rank = i + 1 ;
			sc = sch[i].score ;
		} 
		cout << rank << ' ' << sch[i].name << ' ' << sch[i].score << ' ' <<sch[i].cnt << endl ;
	}
	return 0 ;
}

这篇关于PAT (Advanced Level) Practice 1141 PAT Ranking of Institutions (25 分) 凌宸1642的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!