10116 - Robot Motion
Moderator: Board moderators
-
- New poster
- Posts: 2
- Joined: Thu Oct 24, 2002 10:47 am
- Location: Paris
10116 - Robot Motion
i have a WA and i don't understand why. I think this problem is very simple but maybe i forgot a test...
anyone can help me ?
#include <stdio.h>
void recupere(int rows,int cols,int enter)
{
char c;
int i=0,j=0;
char tab[rows][cols][2];
int compteur=0;
i=0;
while (i<rows)
{
j=0;
while (j<cols)
{
c=getchar();
tab[i][j][0]=c;
tab[i][j][1]=-1;
j++;
}
c=getchar();
i++;
}
i=0;
j=enter-1;
while ((i>=0)&&(i<rows)&&(j>=0)&&(j<cols))
{
char temp=tab[i][j][1];
tab[i][j][1]=(char)compteur;
compteur++;
switch (tab[i][j][0])
{
case 'N':i--;
break;
case 'S':i++;
break;
case 'W':j--;
break;
case 'E':j++;
break;
}
if (temp!=-1)
{
if (temp==0)
printf("%d step(s) before a loop of %d step(s)\n",compteur-1,compteur-1);
else
printf("%d step(s) before a loop of %d step(s)\n",temp,compteur-temp-1);
return;
}
}
printf("%d step(s) to exit\n",compteur);
}
int main()
{
int rows,cols,enter;
while (1)
{
scanf("%d",&rows);
scanf("%d",&cols);
scanf("%d",&enter);
if ((rows==0)&&(cols==0)&&(enter==0))
return 0;
getchar();
recupere(rows,cols,enter);
}
}
@END_OF_SOURCE_CODE ;-)[/c]
anyone can help me ?
#include <stdio.h>
void recupere(int rows,int cols,int enter)
{
char c;
int i=0,j=0;
char tab[rows][cols][2];
int compteur=0;
i=0;
while (i<rows)
{
j=0;
while (j<cols)
{
c=getchar();
tab[i][j][0]=c;
tab[i][j][1]=-1;
j++;
}
c=getchar();
i++;
}
i=0;
j=enter-1;
while ((i>=0)&&(i<rows)&&(j>=0)&&(j<cols))
{
char temp=tab[i][j][1];
tab[i][j][1]=(char)compteur;
compteur++;
switch (tab[i][j][0])
{
case 'N':i--;
break;
case 'S':i++;
break;
case 'W':j--;
break;
case 'E':j++;
break;
}
if (temp!=-1)
{
if (temp==0)
printf("%d step(s) before a loop of %d step(s)\n",compteur-1,compteur-1);
else
printf("%d step(s) before a loop of %d step(s)\n",temp,compteur-temp-1);
return;
}
}
printf("%d step(s) to exit\n",compteur);
}
int main()
{
int rows,cols,enter;
while (1)
{
scanf("%d",&rows);
scanf("%d",&cols);
scanf("%d",&enter);
if ((rows==0)&&(cols==0)&&(enter==0))
return 0;
getchar();
recupere(rows,cols,enter);
}
}
@END_OF_SOURCE_CODE ;-)[/c]
-
- Experienced poster
- Posts: 122
- Joined: Tue Apr 16, 2002 10:07 am
Just cannot get it AC!!!
I tried all the test cases you put... it works fine with my program but still I did not get AC!
Can you please post on new tricky test data?
Thanks in advance...

Can you please post on new tricky test data?
Thanks in advance...
I got WA... too.
Please give me the output according to the following input,
and show me some special test case if you have.
Thank you.
Please give me the output according to the following input,
and show me some special test case if you have.
Code: Select all
2 2 1
SS
EW
2 1 1
S
N
2 2 2
ES
NW
1 1 1
S
0 0 0
[EOF]
Here are answers for your tests.
I don't think there are any special tests.
Code: Select all
1 step(s) before a loop of 2 step(s)
0 step(s) before a loop of 2 step(s)
0 step(s) before a loop of 4 step(s)
1 step(s) to exit
someone who like to solve informatic problems.
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
http://acm.uva.es/cgi-bin/OnlineJudge?AuthorInfo:29650
-
- Learning poster
- Posts: 63
- Joined: Tue Mar 07, 2006 6:51 pm
- Location: india
10116
hi friends i trying to solve 10116 robot motion but its giving WA....i test all the data availble on forum but still its giving WA kindly test my program againts some accepted program..plz....
here is my code...
#include<stdio.h>
#include<string.h>
main()
{
int b[100][100],c[100][100],i,j,m,n,k,u,v;
char a[100][100];
while( scanf("%d%d%d",&m,&n,&k) && ( m||n||k))
{
getchar();
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[j]=getchar();
b[j]=1;
c[j]=0;
}
getchar();
}
k=k-1;
b[0][k]=0;//starting point
u=0,v=0;
for(i=1;;i++)
{
if(a[v][k]=='E')
{
k=k+1;
u=u+1;
if(k>=n)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)//visited
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='S')
{
v=v+1;
u=u+1;
if(v>=m)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)//already visited initially
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='W')
{
k=k-1;
u=u+1;
if(k<0)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='N')
{
v=v-1;
u=u+1;
if(v<0)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
}//forloop
}//while
}//main
here is my code...
#include<stdio.h>
#include<string.h>
main()
{
int b[100][100],c[100][100],i,j,m,n,k,u,v;
char a[100][100];
while( scanf("%d%d%d",&m,&n,&k) && ( m||n||k))
{
getchar();
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
a[j]=getchar();
b[j]=1;
c[j]=0;
}
getchar();
}
k=k-1;
b[0][k]=0;//starting point
u=0,v=0;
for(i=1;;i++)
{
if(a[v][k]=='E')
{
k=k+1;
u=u+1;
if(k>=n)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)//visited
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='S')
{
v=v+1;
u=u+1;
if(v>=m)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)//already visited initially
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='W')
{
k=k-1;
u=u+1;
if(k<0)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
else if(a[v][k]=='N')
{
v=v-1;
u=u+1;
if(v<0)
{
if(u==1)
printf("%d step to exit\n",u);
else
printf("%d step(s) to exit\n",u);
break;
}
else
{
if(b[v][k]==0)
{
if(c[v][k]==1)
printf("%d step before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
else
printf("%d step(s) before a loop of %d step(s)\n",c[v][k],u-c[v][k]);
break;
}
else
{
b[v][k]=0;
c[v][k]=i;
}
}
}
}//forloop
}//while
}//main
-
- New poster
- Posts: 10
- Joined: Tue Nov 07, 2006 2:03 pm
- Location: Jakarta
hi mukeshtiwari,
it said that:
u should add "(s)" on all your print statement...
and maybe remove your comment statement...
Hope u get AC soon.
it said that:
Code: Select all
The word "step" is always immediately followed by "(s)" whether or not the number before it is 1.
and maybe remove your comment statement...
Hope u get AC soon.

Impossible is nothing
-
- Learning poster
- Posts: 63
- Joined: Tue Mar 07, 2006 6:51 pm
- Location: india