|  | 
|  | 
| back to board | Where is my mistake?????? Posted by Sega  31 Jul 2003 12:26This is my program:
 #include<iostream.h>
 
 int **a;
 
 int main()
 {
 int n,i,j,f=0;
 char c;
 cin >> n; cin.get(c);
 a=new int* [n+2];
 a[0]=new int [n+2];
 a[n+1]=new int [n+2];
 for (i=1; i<=n; i++)
 {
 a[i]=new int [n+2];
 for (j=1; j<=n; j++)
 {
 cin.get(c);
 while ((c!='.')&&(c!='#'))
 cin.get(c);
 if (c=='.') a[i][j]=0;
 else a[i][j]=1;
 }
 cin.get(c);
 }
 for (i=0; i<=n+1; i++)
 {
 a[0][i]=1; a[n+1][i]=1;
 a[i][0]=1; a[i][n+1]=1;
 }
 int state=1;
 long len=-3;
 i=1; j=1;
 while ((i!=1)||(j!=1)||(state!=4))
 {
 if ((i==n)&&(j==n)) f=1;
 if (state==1)
 {
 if (a[i-1][j])
 {
 len++;
 if (a[i][j+1]) state=2;
 else j++;
 } else {state=4; i--;}
 } else
 if (state==2)
 {
 if (a[i][j+1])
 {
 len++;
 if (a[i+1][j]) state=3;
 else i++;
 } else {state=1; j++;}
 } else
 if (state==3)
 {
 if (a[i+1][j])
 {
 len++;
 if (a[i][j-1]) state=4;
 else j--;
 } else {state=2; i++;}
 } else
 {
 if (a[i][j-1])
 {
 len++;
 if (a[i-1][j]) state=1;
 else i--;
 } else {state=3; j--;}
 }
 }
 if (!f)
 {
 i=n; j=n; state=3; len++;
 while ((i!=n)||(j!=n)||(state!=2))
 {
 if ((i==n)&&(j==n)) f=1;
 if (state==1)
 {
 if (a[i-1][j])
 {
 len++;
 if (a[i][j+1]) state=2;
 else j++;
 } else {state=4; i--;}
 } else
 if (state==2)
 {
 if (a[i][j+1])
 {
 len++;
 if (a[i+1][j]) state=3;
 else i++;
 } else {state=1; j++;}
 } else
 if (state==3)
 {
 if (a[i+1][j])
 {
 len++;
 if (a[i][j-1]) state=4;
 else j--;
 } else {state=2; i++;}
 } else
 {
 if (a[i][j-1])
 {
 len++;
 if (a[i-1][j]) state=1;
 else i--;
 } else {state=3; j--;}
 }
 }
 }
 cout << 9*len;
 return 0;
 }
 
 I check my program on all tests on forum, it works right!
 If somebody can help me, show me my mistake, please.
 Beforehand thanks.
Did you think about the area can't be got thought from the "Entrance" to the "Exit"?(-) | 
 | 
|