uva 10258 - Contest Scoreboard

本文介绍了一个用于ACM竞赛的排名系统实现方法,通过C语言进行编程,使用结构体来存储队伍信息,包括解题数量、总用时及错误提交罚时等,并通过qsort函数对队伍进行排序。

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

题意  写个rank

连接点击打开链接


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX 105

struct list
{
	int num[20], time;
	bool flag[20];
	int count;
	bool submit;
	int x;
}s[MAX];

void initialize ( )
{
	for ( int i = 0; i < MAX; i++ )
	{
		for ( int j = 0; j < 20; j++ )
		{
			s[i].num[j] = 0;
			s[i].flag[j] = false;
		}
		s[i].time = 0;
		s[i].x = i;
		s[i].count = 0;
		s[i].submit = false;
	}
}

int cmp ( const void *a, const void *b )
{
	list *q, *p;
	q = ( list * )a;
	p = ( list * )b;
	if ( q->count > p->count )
		return -1;
	if ( q->count < p->count )
		return 1;
	if ( q->time > q->time )
		return 1;
	else
		return -1;
}

void solve ( )
{
	initialize ( );
	char str[1000];
	while ( gets ( str ) )
	{
		if ( strlen ( str ) < 2 )
			break;
		int troop, title, time;
		char state;
		sscanf ( str, "%d%d%d %c", &troop, &title, &time, &state );
		s[troop].submit = true;
		if ( state == 'C' && !s[troop].flag[title] )
		{
			s[troop].count++;
			s[troop].flag[title] = true;
			s[troop].time += time + s[troop].num[title];
		}
		if ( state == 'I' )
			s[troop].num[title] += 20;
	}
	qsort ( s, MAX, sizeof s[0], cmp );
	for ( int i = 0; i < MAX; i++ )
		if ( s[i].submit )
			printf ( "%d %d %d\n", s[i].x, s[i]. count, s[i].time );
}

int main ( )
{
	int t;
	scanf ( "%d\n\n", &t );
	while ( t-- )
	{
		solve ( );
		if ( t )
			puts ( "" );
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值