1 import java.util.Scanner; 2 3 public class Main { 4 5 public static void main(String[] args) { 6 char[] lz = { 'L', 'D', 'R', 'U' }; // 左轉方向數組 7 char[] rz = { 'L', 'U', 'R', 'D' }; // 右轉方向數組 8 9 Scanner in = new Scanner(System.in); 10 int n = in.nextInt(); 11 int m = in.nextInt(); 12 13 int[][] maps = new int[n][m]; 14 for (int i = 0; i < n; i++) 15 for (int j = 0; j < m; j++) 16 maps[i][j] = in.nextInt(); 17 18 int x = in.nextInt(); 19 int y = in.nextInt(); 20 char s = in.next().trim().charAt(0); 21 int k = in.nextInt(); 22 23 for (int j = 0, i = 0; j < k; j++) { 24 if (maps[x][y] == 1) { // 黑色格子 右轉90度 25 maps[x][y] = 0; // 置為白色格子 26 for (i = 0; i < 4; i++) 27 if (rz[i] == s) 28 break; 29 s = rz[(i + 1) % 4]; 30 switch (s) { 31 case 'L': 32 y--; 33 break; 34 case 'R': 35 y++; 36 break; 37 case 'U': 38 x--; 39 break; 40 case 'D': 41 x++; 42 break; 43 } 44 } else { // 白色格子 左轉90度 45 maps[x][y] = 1; // 置為黑色格子 46 for (i = 0; i < 4; i++) 47 if (lz[i] == s) 48 break; 49 s = lz[(i + 1) % 4]; 50 switch (s) { 51 case 'L': 52 y--; 53 break; 54 case 'R': 55 y++; 56 break; 57 case 'U': 58 x--; 59 break; 60 case 'D': 61 x++; 62 break; 63 } 64 } 65 } 66 System.out.println(x + " " + y); 67 } 68 }