2009年3月2日 星期一

Q10188: Automated Judge Script

/*
Note:
1

2


這樣是PE

2
10188
2005
3
101
88
2005
這樣是PE
Run time: 0.000
*/
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define AC 0
#define PE 1
#define WA 2
#define SIZE 120
#define N 100
char ans[N][SIZE+1];
char str[N][SIZE+1];
int accept(int n);
int present(int n, int m);

void print(int n);

int main()
{
int n, m;
int i;
int state;
while (scanf("%d", &n))
{
if (!n) break;

state = WA;

// getchar 不要放在scanf裡
getchar();

for ( i = 0; i < n; i++)
gets(ans[i]);

scanf("%d", &m);

// getchar 不要放在scanf裡
getchar();

for ( i = 0; i < m; i++)
gets(str[i]);

if (n == m)
{
if (accept(n))
{
state = AC;
print(state);
continue;
}
}

if (present(n, m))
{
state = PE;
print(state);
continue;
}

print(state);

}

return 0;
}

int accept(int n)
{
int i, j;
for ( i = 0; i < n; i++)
if (strcmp(ans[i], str[i]))
return false;

return true;
}

int present(int n, int m)
{
int i, j, k;
char s1[N*SIZE];
char s2[N*SIZE];

for ( i = 0, k = 0; i < n; i++)
for ( j = 0; ans[i][j] != '\0'; j++)
if (isdigit(ans[i][j]))
s1[k++] = ans[i][j];

s1[k] = '\0';

for ( i = 0, k = 0; i < m; i++)
for ( j = 0; str[i][j] != '\0'; j++)
if (isdigit(str[i][j]))
s2[k++] = str[i][j];

s2[k] = '\0';

if (!strcmp(s1, s2))
return true;
else
return false;
}

void print(int n)
{
static int run;

if (n == AC)
printf("Run #%d: Accepted\n", ++run);

else
if (n == PE)
printf("Run #%d: Presentation Error\n", ++run);

else
if (n == WA)
printf("Run #%d: Wrong Answer\n", ++run);

}

沒有留言: