Hi,
I have been on this problem for days now, and I keep getting WA. Any special/border/tricky/unspecified-in-the-question test cases?
How should we handle lines that are only composed of white spaces?
If an essential is present in the submitout file, but crosses a line boundary over to the next line, is it counted? For example, [abcde] is the essential and the submitout file is
abc
de
Thanks.
Code: Select all
/*
Presentation Error, 292
Status: WA
*/
#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <cstring>
using namespace std;
int nj, ns, tc, N;
char sub[12][100], jury[12][100], P[1000], T[100];
void straighten() {
P[0] = 0;
for(int i = 0; i < ns; i++)
strcat(P, sub[i]);
}
int main() {
scanf("%d\n", &tc);
char temp[100];
while(tc--) {
// Input size
gets(temp);
nj = atoi(temp);
int i;
for(i = 1; temp[i-1] != ' '; i++)
;
ns = atoi(temp+i);
// Juryout input
for(int j = 0; j < nj; j++) {
gets(temp);
if(temp[0] == 0) { j--; nj--; continue; }
int i = 0;
while(temp[i] == ' ' || temp[i] == '\t')
i++;
if(temp[i] == 0) { j--; nj--; continue; }
strcpy(jury[j], temp);
while(temp[i])
i++;
while(temp[i-1] == ' ' || temp[i-1] == '\t')
i--;
jury[j][i] = 0;
}
// Submitout input
for(int j = 0; j < ns; j++) {
gets(temp);
if(temp[0] == 0) { j--; ns--; continue; }
int i = 0;
while(temp[i] == ' ' || temp[i] == '\t')
i++;
if(temp[i] == 0) { j--; ns--; continue; }
strcpy(sub[j], temp);
while(temp[i])
i++;
while(temp[i-1] == ' ' || temp[i-1] == '\t')
i--;
sub[j][i] = 0;
}
// Accepted?
if(nj == ns) {
char cmp[100];
int i;
for(i = 0; i < nj; i++) {
int p = 0;
for(int j = 0; jury[i][j]; j++)
if(jury[i][j] != '[' && jury[i][j] != ']')
cmp[p++] = jury[i][j];
cmp[p] = 0;
if(strcmp(cmp, sub[i]))
break;
}
if(i == nj) {
printf("Accepted\n");
continue;
}
}
// Convert to uppercase
for(int i = 0; i < nj; i++)
for(int j = 0; jury[i][j]; j++)
jury[i][j] = toupper(jury[i][j]);
for(int i = 0; i < ns; i++)
for(int j = 0; sub[i][j]; j++)
sub[i][j] = toupper(sub[i][j]);
// WA / Presentation Error?
straighten();
char *ptr = P;
for(int i = 0; i < nj; i++) {
for(int j = 0; jury[i][j]; j++)
if(jury[i][j] == '[') {
for(N = 0, ++j; jury[i][j] != ']'; j++)
T[N++] = jury[i][j];
T[N] = 0;
ptr = strstr(ptr, T);
if(!ptr) {
printf("Wrong Answer\n");
goto end;
}
ptr += N;
}
}
printf("Presentation Error\n");
end: {
continue;
}
}
return 0;
}