Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 1035
It indicates that this question is very simple and basically there is no trap. As for WA, I did not set the start point to 1 twice, that is, I added 1 more to the start point.
# Include <iostream> # include <string. h> # include <stdio. h> using namespace STD; # define maxn 20int map [maxn] [maxn]; char rec [maxn] [maxn]; int find_ans (INT t) {int I = 1, j = T, step = 1; if (REC [I] [J] = 0) {printf ("% d step (s) to exit \ n", 0 ); return 0;} map [I] [J] = 1; while (1) {Switch (REC [I] [J]) {Case 'N': I --; break; case's ': I ++; break; Case 'E': J ++; break; Case 'W': J --; break;} Step ++; if (Map [I] [J]> 0) {printf ("% d step (s) before a loop of % d step (s) \ n ", map [I] [J]-1, step-map [I] [J]); Return 0;} If (REC [I] [J] = 0) {printf ("% d step (s) to exit \ n", step-1); Return 0;} else map [I] [J] = step ;} return 0;} int main () {int n, m, T, I; while (scanf ("% d", & N, & M )) {If (n = 0 & M = 0) return 0; scanf ("% d", & T); memset (MAP, 0, sizeof (MAP )); memset (REC, 0, sizeof (REC); for (I = 1; I <= N; I ++) scanf ("% s ", REC [I] + 1); find_ans (t);} return 0 ;}