uva 10188 - Automated Judge Script

本文介绍了一个简单的判题程序实现,该程序能够判断提交的答案是否正确(AC),呈现错误(PE)还是答案错误(WA)。通过字符串比较和数字提取来验证答案的一致性和格式正确性。

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

题意:写一个judge脚本,判断WA,PE,AC;

算法:简单模拟;

连接:点击打开链接


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

void judge ( char answer[MAX][MAX], char test[MAX][MAX], const int n, const int m )
{
	int i, j, k = 0, g = 0;
	if ( n == m )
	{
		bool flag = true;
		for ( i = 0; i < n; i++ )
			if ( strcmp ( answer[i], test[i] ) )
			{
				flag = false;
				break;
			}
		if ( flag )
		{
			puts ( "Accepted" );
			return ;
		}
	}
	char str[MAX*MAX], ch[MAX*MAX];
	for ( i = 0; i < n; i++ )
	{
		int len = strlen ( answer[i] );
		for ( j = 0; j < len; j++ )
			if ( '0' <= answer[i][j] && answer[i][j] <= '9' )
				str[k++] = answer[i][j];
	}
	str[k] = 0;
	for ( i = 0; i < m; i++ )
	{
		int len = strlen ( test[i] );
		for ( j = 0; j < len; j++ )
			if ( '0' <= test[i][j] && test[i][j] <= '9' )
				ch[g++] = test[i][j];
	}
	ch[g] = 0;
	if ( !strcmp ( ch, str ) )
	{
		puts ( "Presentation Error" );
		return ;
	}
	puts ( "Wrong Answer" );
}

int main ( )
{
	int n, m, t = 1;
	while ( ~scanf ( "%d", &n ) && n )
	{
		getchar ( );
		char answer[MAX][MAX], test[MAX][MAX];
		for ( int i = 0; i < n; i++ )
			gets ( answer[i] );
		scanf ( "%d", &m );
		getchar ( );
		for ( int j = 0; j < m; j++ )
			gets ( test[j] );
		printf ( "Run #%d: ", t++ );
		judge ( answer, test, n, m);
	}
	return 0;
}


评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值