1025. PAT Ranking (25) [排序]

本文介绍了一种算法,用于合并多个地点的Programming Ability Test(PAT)竞赛成绩,并生成最终的排名列表。算法首先对各考场的成绩进行局部排序和排名,然后合并所有考场的成绩,按总分和注册号排序,生成全局排名。

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

Programming Ability Test (PAT) is organized by the College of Computer Science and Technology of Zhejiang University. Each test is supposed to run simultaneously in several places, and the ranklists will be merged immediately after the test. Now it is your job to write a program to correctly merge all the ranklists and generate the final rank.

Input Specification:

Each input file contains one test case. For each case, the first line contains a positive number N (≤100), the number of test locations. Then N ranklists follow, each starts with a line containing a positive integer K (≤300), the number of testees, and then K lines containing the registration number (a 13-digit number) and the total score of each testee. All the numbers in a line are separated by a space.

Output Specification:

For each test case, first print in one line the total number of testees. Then print the final ranklist in the following format:

registration_number final_rank location_number local_rank
1
The locations are numbered from 1 to N. The output must be sorted in nondecreasing order of the final ranks. The testees with the same score must have the same rank, and the output must be sorted in nondecreasing order of their registration numbers.

Sample Input:

2
5
1234567890001 95
1234567890005 100
1234567890003 95
1234567890002 77
1234567890004 85
4
1234567890013 65
1234567890011 25
1234567890014 100
1234567890012 85

Sample Output:

9
1234567890005 1 1 1
1234567890014 1 2 1
1234567890001 3 1 2
1234567890003 3 1 2
1234567890004 5 1 4
1234567890012 5 2 2
1234567890002 7 1 5
1234567890013 8 2 3
1234567890011 9 2 4

//先对同一考场考生排序排名,再对全体考生排序排名 
#include<cstdio> 
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;

//定义学生结构体 
struct Student{
	char registration_number[15]; //准考证号 
	int total_score; //总分 
	int location_number; //考场号 
	int local_rank; //考场内排名 
}stu[30010];	//注意这里的取值 **题目规定不超过100个考场,每个考场不超过300个人,所以该值不小于100×300=30000人。  

//定义比较函数 
bool cmp(Student a, Student b){
	if (a.total_score!=b.total_score) return a.total_score > b.total_score; 
	else return strcmp(a.registration_number,b.registration_number)<0; 
}

int main(){
	int n, k, num=0; // n 考场数; k 当前考场人数; num 总考生数
	scanf("%d",&n); 
	
	//分考场输入考生信息 
	for(int i=1; i<=n; i++){
		//该考场人数 
		scanf("%d",&k); 
		//输入每位考生的准考证号,总分,考场号
		for(int j=0;j<k;j++){
			scanf("%s %d",stu[num].registration_number, &stu[num].total_score); 
			stu[num].location_number=i; 
			num++; //总考生数 ++ 
		}	
		//考场内排序
		sort(stu+num-k, stu+num, cmp);	//num-k即(5-5或9-4)保证两个考场都适用
		//考场内排名
		stu[num-k].local_rank=1; 
		for(int j=num-k+1; j<num; j++){
			if(stu[j].total_score==stu[j-1].total_score){ //与前一名总分相同,前一名的名次给后一名 
				stu[j].local_rank = stu[j-1].local_rank;
			}
			else{		//否则,后一名的排名+1(num-k使得两个考场都适用)
				stu[j].local_rank = j+1-(num-k);
			}
		}
	}

	//输出总考生数 
	printf("%d\n",num);
	
	//对所有考生排序
	sort(stu, stu+num, cmp) ;
	
	//对所有考生排名;输出每位学生的准考证号,总排名,考场号,考场排名 
	int final_rank=1;
	for(int i=0; i<num; i++){
		if(i>0 && stu[i].total_score!=stu[i-1].total_score){
			final_rank=i+1;
		}
		printf("%s %d %d %d\n",stu[i].registration_number,final_rank,stu[i].location_number,stu[i].local_rank);
	}
	
	return 0;
}
资源下载链接为: https://pan.quark.cn/s/9e7ef05254f8 在网页设计中,为图片添加文字是一种常见的需求,用于增强视觉效果或传达更多信息。本文将介绍两种常用的方法:一种是将图片设置为背景并添加文字;另一种是利用<span>标签结合CSS定位来实现。 这种方法通过CSS实现,将图片设置为一个容器(通常是<div>)的背景,然后在容器中添加文字。具体步骤如下: 创建一个包含文字的<div>元素: 使用CSS设置<div>的背景图片,并调整其尺寸以匹配图片大小: 如有需要,可使用background-position属性调整图片位置,确保文字显示在合适位置。这样,文字就会显示在图片之上。 另一种方法是将文字放在<span>标签内,并通过CSS绝对定位将其放置在图片上。步骤如下: 创建一个包含图片和<span>标签的<div>: 设置<div>为相对定位,以便内部元素可以相对于它进行绝对定位: 设置<span>为绝对定位,并通过调整top和left属性来确定文字在图片上的位置: 这种方法的优点是可以精确控制文字的位置,并且可以灵活调整文字的样式,如颜色和字体大小。 两种方法各有优势,可根据实际需求选择。在实际开发中,还可以结合JavaScript或jQuery动态添加文字,实现更复杂的交互效果。通过合理运用HTML和CSS,我们可以在图片上添加文字,创造出更具吸引力的视觉效果。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值