10188 - Automated Judge Script

All about problems in Volume 101. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

10188 - Automated Judge Script

Post by Caesum » Tue Jun 18, 2002 8:54 pm

The problem seems simple enough, but why so many WA's on this question, and why do I keep getting WA ?

I compare digits of both input:
If not equal then the answer is WA
I compare inputs in entirety:
If not equal then the answer is PE
Otherwise the answer is AC

A lot of people in the comments are making comments about spaces and \n's but this is not what the question is stating. The question clearly states:
ALL characters must match and must be in the same order
and ALL has been put into capitals for emphasis. Removing spaces and \n's does not help. (note: backslashes might not show up in forum)

So can anyone confirm what is wrong with this one ? Presumably there is some bad judge data here ?

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev » Tue Jun 18, 2002 10:14 pm

How do you read input? If you're using scanf() you can get incorrect results (PE instead of AC), so best choice is to use only gets().

Caesum
Experienced poster
Posts: 225
Joined: Fri May 03, 2002 12:14 am
Location: UK
Contact:

gets

Post by Caesum » Tue Jun 18, 2002 10:23 pm

Actually I am using gets...... and I just thought a bit more carefully about this and realised that gets removes the newline character which was causing my problem since I simply concatenated all input together without newlines. Added a strcat(lines,"\n") before adding the next line and it works perfectly :)

Was mislead by peoples comments in their tag lines..... :oops:

liusu
New poster
Posts: 22
Joined: Thu Aug 01, 2002 10:26 am

help!

Post by liusu » Wed Aug 28, 2002 2:27 pm

i got WA again and again,please help me?what's the problem?or give me some sample input and output?
:oops:

chaojinn
New poster
Posts: 6
Joined: Fri Apr 19, 2002 12:34 pm

i use getchar() and strcat() but got w/a,help!

Post by chaojinn » Thu Sep 12, 2002 3:54 pm

#include "iostream.h"
#include "string.h"
#include "stdio.h"
#include "fstream.h"

void noblank(char str[])
{
long l=strlen(str);
long i,j;
for(i=0;i<l;i++)
{
if(!(str>='0'&&str<='9'))
{
for(j=i;j<l-1;j++)
{
str[j]=str[j+1];
}
l--;
str[l]='\0';
i=-1;
}
}
}

void main()
{
bool ac,wa,pe;
long index=1;
long n;
while(cin>>n)
{
if(n==0)
break;
ac=wa=pe=false;
char table[12000];
strcpy(table,"");
long i=0;
while(i<n)
{
char t=getchar();
if(t=='\n')
i++;
char tt[2];
tt[0]=t;
tt[1]='\0';
strcat(table,tt);
}
long nn;
cin>>nn;
char tab[12000];
strcpy(tab,"");
i=0;
while(i<nn)
{
char t=getchar();
if(t=='\n')
i++;
char tt[2];
tt[0]=t;
tt[1]='\0';
strcat(tab,tt);
}
if(strcmp(table,tab))
{
noblank(table);
noblank(tab);
if(!strcmp(table,tab))
{
pe=true;
}
else
{
wa=true;
}

}
if((!wa)&&(!pe))
ac=true;
if(wa)
cout<<"Run #"<<index<<": Wrong Answer"<<endl;
if(pe)
cout<<"Run #"<<index<<": Presentation Error"<<endl;
if(ac)
cout<<"Run #"<<index<<": Accepted"<<endl;
index++;
}



}

dabendan
New poster
Posts: 13
Joined: Mon May 06, 2002 4:05 pm
Location: ROC

Post by dabendan » Sat Dec 07, 2002 6:08 pm

what is the output if my input is:
3
Input Set #1: YES
Input Set #2: NO
Input Set #3: NO
4
123
ABCDE FG
hij k
lmn
0

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one » Mon Dec 23, 2002 7:29 pm

I get runtime error sigsegv for this
what is invalid memory reference? could anyone helped me out?
I used 4 char array with 1000 array of element each for this problem.

yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

Post by yatsen » Tue Dec 24, 2002 8:08 am

Can anyone who got AC put some test cases?
I got WA but I do not know what is wrong. Thanks.

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one » Tue Dec 24, 2002 10:34 am

ok I've taken care of sigsegv, now I get WA like everyone else here, well except for Caesum and Ivan of course, it run 0.025 sec before it declared to be WA.
ummm, same question with yatsen pls

Ivan Golubev
Experienced poster
Posts: 167
Joined: Fri Oct 19, 2001 2:00 am
Location: Saint Petersburg, Russia

Post by Ivan Golubev » Tue Dec 24, 2002 1:56 pm

I think that input reading routine is a most important part in this problem. Once you've read everything correct, everything else is trivial.

In my accepted solution this part looks like:[c] while (gets(s) != NULL) {
n1 = atol(s);
if (n1 == 0) break;
p1 = (char *)malloc(128 * n1);
for (i=0; i<n1; i++) gets(&p1[i*128]);
gets(s);
n2 = atol(s);
p2 = (char *)malloc(128 * n2);
for (i=0; i<n2; i++) gets(&p2[i*128]);
...
}[/c]Now you can compare these strings like:[c]if (strcmp(&p1[index1*128], &p2[index2*128])) ...[/c]And, of course, don't forget to free p1 & p2 after calculations.

And correct answer for dabendan's input is PE.

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one » Tue Dec 24, 2002 2:18 pm

aaaaah

I've found my mistake , after changing the line

strcpy (result,"");

into

for (i=0;i<MAX;i++)
result = '\0';

it get accepted right away.
and also I used the strcat (result,"\n") like Caesum said
it worked out fine.

let me give sample input
3
adfs df 1 dasf adf df
2
fs aaaaaaaaaaaa 3
3
aa1
2
3

sample output
Run #1: Presentation Error

yatsen
Learning poster
Posts: 68
Joined: Fri Nov 23, 2001 2:00 am
Location: taiwan

Post by yatsen » Wed Dec 25, 2002 9:01 am

Ivan Golubev wrote:I think that input reading routine is a most important part in this problem. Once you've read everything correct, everything else is trivial.
Yes, you are right. After I change my while(scanf("%d\n",&n)==1) to while(gets(line)!=NULL), I got AC. :D

But my check order is different from Caesum's.
I check AC first, then check PE, otherwise WA.
I think it is easier for me.

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:

Post by supermin » Sat Jan 11, 2003 8:17 pm

After changing the way as yatsen does , I got AC.

But I still don't know why can't use

Code: Select all

while(scanf("%d",&n) && n)  
    scanf("\n");
Could anyone explain it clearly? Maybe some examples are helpful.

Thanks!
Last edited by supermin on Sun Jan 12, 2003 3:36 am, edited 1 time in total.

Adrian Kuegel
Guru
Posts: 724
Joined: Wed Dec 19, 2001 2:00 am
Location: Germany

Post by Adrian Kuegel » Sat Jan 11, 2003 8:50 pm

scanf("\n") does not only read one '\n' character, it does read all whitespace characters. Try it out!

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:

Post by supermin » Sun Jan 12, 2003 3:35 am

Oh , I see . Thank you very much! :D

Post Reply

Return to “Volume 101 (10100-10199)”