/
10188_1.cpp
executable file
·115 lines (95 loc) · 1.97 KB
/
10188_1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define sz 12005 //100*120
char *strncat(char *string1, char *string2, int length);
int PE(char *correct,char *output);
int comp(void const *A, void const *B)
{ char *a = (char*)A;
char *b = (char*)B;
return *a - *b;
}
void main()
{
char correct[sz],output[sz],a[125];
long i,n,m,len;
long cases=1;
while (gets(a) != NULL)
{
n = atol(a);
if (n == 0) break;
for(i=0;i<n;i++)
{
gets(a);
if(i==0)
strcpy(correct,a);
else
{
len = strlen(a);
strncat(correct,a,len);
}
}
gets(a);
m = atol(a);
for(i=0;i<m;i++)
{
gets(a);
if(i==0)
strcpy(output,a);
else
{
len = strlen(a);
strncat(output,a,len);
}
}
if(m==n && strcmp(correct,output)==0)
printf("Run #%ld: Accepted\n",cases++);
else
{
//if(m==n && PE(correct,output)==1)
if(PE(correct,output)==1)
printf("Run #%ld: Presentation Error\n",cases++);
else
printf("Run #%ld: Wrong Answer\n",cases++);
}
}
}
int PE(char *correct,char *output)
{
long i,len,p;
char temp1[sz],temp2[sz];
len = strlen(correct);
p=0;
for(i=0;i<len;i++)
{
if(correct[i]>='0'&&correct[i]<='9')
temp1[p++]=correct[i];
}
temp1[p]='\0';
qsort(temp1,p,sizeof(temp1[0]),comp);
p=0;
len = strlen(output);
for(i=0;i<len;i++)
{
if(output[i]>='0'&&output[i]<='9')
temp2[p++]=output[i];
}
temp2[p]='\0';
//printf("%s\n%s\n",correct,output);
//printf("%s %s\n",temp1,temp2);
qsort(temp2,p,sizeof(temp2[0]),comp);
if(strcmp(temp1,temp2)==0)
return 1;
return 0;
}
//Append the 1st 'length' characters of 'string2' at the end of 'string1'.
char *strncat(char *string1, char *string2, int length)
{
int i, j;
for(i = 0, j = strlen(string1); i < length && string2[i] != NULL; i++, j++)
{
string1[j] = string2[i];
}
string1[j] = NULL;
return(string1);
}