Automated Judge Script

Automated Judge Script

时间: 1ms        内存:64M

描述:

Human programming contest judges are known to be very picky. To eliminate the need for them, write an automated judge script to judge submitted solution runs.

Your program should take a file containing the correct output as well as the output of submitted program and answer either Accepted, Presentation Error, or Wrong Answer, defined as follows:

Accepted:
You are to report ``Accepted'' if the team's output matches the standard solution exactly. All characters must match and must occur in the same order.

Presentation Error:
Give a ``Presentation Error'' if all numeric characters match in the same order, but there is at least one non-matching non-numeric character. For example, ``15 0'' and ``150'' would receive ``Presentation Error'', whereas ``15 0'' and ``1 0'' would receive ``Wrong Answer,'' described below.

Wrong Answer:
If the team output cannot be classified as above, then you have no alternative but to score the program a `Wrong Answer'.

输入:

The input will consist of an arbitrary number of input sets. Each input set begins with a line containing a positive integer n < 100, which describes the number of lines of the correct solution. The next n lines contain the correct solution. Then comes a positive integer m < 100, alone on its line, which describes the number of lines of the team's submitted output. The next m lines contain this output. The input is terminated by a value of n = 0, which should not be processed. No line will have more than 100 characters.

输出:

For each set, output one of the following:

Run #x: Accepted

Run #x: Presentation Error

Run #x: Wrong Answer

where x stands for the number of the input set (starting from 1).

示例输入:

2
The answer is: 10
The answer is: 5
2
The answer is: 10
The answer is: 5
2
The answer is: 10
The answer is: 5
2
The answer is: 10
The answer is: 15
2
The answer is: 10
The answer is:  5
2
The answer is: 10
The answer is: 5
3
Input Set #1: YES
Input Set #2: NO
Input Set #3: NO
3
Input Set #0: YES
Input Set #1: NO
Input Set #2: NO
1
1 0 1 0
1
1010
1
The judges are mean!
1
The judges are good!
0

示例输出:

Run #1: Accepted
Run #2: Wrong Answer
Run #3: Presentation Error
Run #4: Wrong Answer
Run #5: Presentation Error
Run #6: Presentation Error

提示:

参考答案(内存最优[772]):

#include"stdio.h"
#include"string.h"
char a[101][101],b[101][101];
int ac(int n)
{
	int i;
	for(i=0;i<n;i++)
		if(strcmp(a[i],b[i])!=0)
			return 0;//pe|wa
	return 1;//ac 1
}
int pe(int n)
{
	char c[101]={0},d[101]={0};
	int i,j,k=0;
	for(i=0;i<n;i++)
		for(j=0;a[i][j]!='\0';j++)
			if(a[i][j]>='0'&&a[i][j]<='9')
				c[k++]=a[i][j];
	k=0;
	for(i=0;i<n;i++)
		for(j=0;b[i][j]!=0;j++)
			if(b[i][j]>='0'&&b[i][j]<='9')
				d[k++]=b[i][j];
	if(strcmp(c,d)==0)
		return 0;//pe
	else
		return 2;//wa
}
int main()
{

	int n,m,i;
	int flag,count=1;//WA 2 PE 0 AC 1
	while(scanf("%d",&n)&&n)
	{
		getchar();
		for(i=0;i<n;i++)
			gets(a[i]);
		scanf("%d",&m);
		getchar();
		for(i=0;i<m;i++)
			gets(b[i]);
		if(n!=m)
			flag=2;//wa
		else
		{
			flag=ac(n);
			if(flag==0)//pe|wa
				flag=pe(n);
		}
		if(flag==1)
			printf("Run #%d: Accepted\n",count++);
		else if(flag==0)
			printf("Run #%d: Presentation Error\n",count++);
		else
			printf("Run #%d: Wrong Answer\n",count++);
	}
	return 0;
}

参考答案(时间最优[0]):

#include"stdio.h"
#include"string.h"
char a[101][101],b[101][101];
int ac(int n)
{
	int i;
	for(i=0;i<n;i++)
		if(strcmp(a[i],b[i])!=0)
			return 0;//pe|wa
	return 1;//ac 1
}
int pe(int n)
{
	char c[101]={0},d[101]={0};
	int i,j,k=0;
	for(i=0;i<n;i++)
		for(j=0;a[i][j]!='\0';j++)
			if(a[i][j]>='0'&&a[i][j]<='9')
				c[k++]=a[i][j];
	k=0;
	for(i=0;i<n;i++)
		for(j=0;b[i][j]!=0;j++)
			if(b[i][j]>='0'&&b[i][j]<='9')
				d[k++]=b[i][j];
	if(strcmp(c,d)==0)
		return 0;//pe
	else
		return 2;//wa
}
int main()
{

	int n,m,i;
	int flag,count=1;//WA 2 PE 0 AC 1
	while(scanf("%d",&n)&&n)
	{
		getchar();
		for(i=0;i<n;i++)
			gets(a[i]);
		scanf("%d",&m);
		getchar();
		for(i=0;i<m;i++)
			gets(b[i]);
		if(n!=m)
			flag=2;//wa
		else
		{
			flag=ac(n);
			if(flag==0)//pe|wa
				flag=pe(n);
		}
		if(flag==1)
			printf("Run #%d: Accepted\n",count++);
		else if(flag==0)
			printf("Run #%d: Presentation Error\n",count++);
		else
			printf("Run #%d: Wrong Answer\n",count++);
	}
	return 0;
}

题目和答案均来自于互联网,仅供参考,如有问题请联系管理员修改或删除。

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注