Question:
Determine the direction based on newe in the given matrix. If it can exit, the output is
10 step (s) to exit
Output if not available
3 step (s) before a loop of 8 step (s)
Analysis:
Water question, but like the dfs I 've done over the past few days, it's just in the form of = B. It's a waste of time for me to debug and write something special.
Problems:
1. initialize the boundary for a while and find that the row and column are wrong... Else //
2. When you set the tag array, there are many problems. Finally, we should avoid Path = 2 and overwrite it with Path = 1 as 1.
Ah, with a lot of tags set, the readability becomes weaker.>, <....
# Include <stdio. h> # include <string. h> int main () {int row, Col, start; int I, j, X, Y, path [15] [15], Count, flag, FF, F1; char A [15] [15]; while (scanf ("% d", & Row, & Col, & START )! = EOF) {COUNT = 0; FF = 0; F1 = 0; flag = 0; for (I = 0; I <15; I ++) for (j = 0; j <15; J ++) path [I] [J] = 0; If (ROW = 0 & Col = 0 & START = 0) break; for (I = 1; I <= row; I ++) {scanf ("% s", & A [I] [1]) ;}for (I = 0; I <row + 2; I ++) {A [I] [0] = '0'; A [I] [col + 1] = '0 ';} // A [I] [0] = '\ 0'; for (I = 0; I <Col + 2; I ++) {A [0] [I] = '0'; A [row + 1] [I] = '0 ';} // A [0] [I] = '\ 0'; X = 1; y = start; while (1) {If (path [x] [Y]! = 2) path [x] [Y] = 1; // how to avoid Path = 2 and overwrite it to 1. If (A [x] [Y] = '0') break; If (path [x] [Y] = 2 & F1 = 1) break; else if (path [x] [Y] = 2) F1 = 1; if (a [x] [Y] = 'n') {X --; count ++;} else if (a [x] [Y] = 's') {x ++; count ++ ;} else if (a [x] [Y] = 'E') {y ++; count ++ ;} else if (a [x] [Y] = 'W') {y --; count ++;} If (path [x] [Y] = 1) {flag ++; If (FF = 0) {FF = 1; path [x] [Y] = 2 ;}} if (flag = 0) printf ("% d step (s) to exit \ n", count); else printf ("% d step (s) before a loop of % d step (s) \ n ", Count-2 * flag, flag);} return 0 ;}