http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=1590
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
1 #include <stdio.h> 2 #include <string.h> 3 int n,m,s_x,s_y,e_x,e_y; 4 char map[15][15]; 5 6 int Deal(char c) 7 { 8 if(c=='R'&&map[s_x][s_y+1]!='#') 9 { 10 s_y++; 11 if (s_x==e_x&&s_y==e_y) 12 return 1; 13 } 14 else if(c=='L'&&map[s_x][s_y-1]!='#') 15 { 16 s_y--; 17 if (s_x==e_x&&s_y==e_y) 18 return 1; 19 } 20 else if(c=='U'&&map[s_x-1][s_y]!='#') 21 { 22 s_x--; 23 if (s_x==e_x&&s_y==e_y) 24 return 1; 25 } 26 else if(c=='D'&&map[s_x+1][s_y]!='#') 27 { 28 s_x++; 29 if (s_x==e_x&&s_y==e_y) 30 return 1; 31 } 32 return 0; 33 } 34 int main() 35 { 36 char str[120],s[15][15]; 37 scanf("%d %d",&n,&m); 38 memset(map,'#',sizeof(s));//初始化全为墙 39 for (int i = 0; i < n; i ++) 40 { 41 scanf("%s",s[i]); 42 for (int j = 0; j < m; j ++) 43 { 44 45 if (s[i][j]=='S') 46 { 47 s_x = i+1; 48 s_y = j+1; 49 } 50 if (s[i][j]=='T') 51 { 52 e_x = i+1; 53 e_y = j+1; 54 } 55 map[i+1][j+1] = s[i][j];//给图像周围增加一堵墙,防止出界 56 57 } 58 } 59 60 int ans = 0,k; 61 scanf("%d",&k); 62 scanf("%s",str); 63 for (int i = 0; i < k; i ++) 64 { 65 ans = Deal(str[i]); 66 if (ans) 67 break; 68 } 69 if (ans) 70 puts("Yes"); 71 else 72 puts("No"); 73 return 0; 74 }