import java.util.Scanner; public class testB { protected int dir = 0; protected int x = 0; protected int y = 0; private static final int[][] MOVING_DIR = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}}; public static void main(String[] args) { Scanner sc = new Scanner(System.in); int t = sc.nextInt(); int n = sc.nextInt(); int m = sc.nextInt(); String[] commons = new String[m + 1]; for (int y = 1; y <= t; y++) { System.out.println("Case #" + y + ":"); for (int i = 0; i < m + 1; i++) { commons[i] = sc.nextLine().replace(" ", ""); } commit(commons, n * (-1)+1); } System.out.println(); } public static void commit(String[] z, int n) { testB main = new testB(); for (String com : z) { if (com.equals("L")) { //遇到左转L指令 main.changeDir(com); //改变方向 } else if (com.equals("R")) { //遇到R右转指令 main.changeDir(com); } else if (com.contains("G")) { //遇到数字累加数字 main.move(Integer.parseInt(com.substring(1)), n); } else if (com.equals("P")) { //遇到R右转指令 main.PRINT(n); } } } public void changeDir(String dir) { this.dir += (dir.equals("L") ? -1 : (dir.equals("R") ? 1 : 0)); } public void move(int value, int n) { dir %= 4; dir += (dir < 0) ? 4 : 0; x += value * MOVING_DIR[dir][0]; y += value * MOVING_DIR[dir][1]; if (x <= 0 && y > 0) { x = 0; y = 0; } else if (x > 0&&x<=n*(-1) && y <= 0&&y>=n) { //符合 } else if (x < 0 && y <= 0&&y>=n) { x = 0; } else if (y<n) { y = n; }else if (x>n*(-1)) { x = n*(-1); } else if (x > 0&&x<=n*(-1) && y >0) { y = 0; } } public void PRINT(int n) { System.out.println(x + " " + y*(-1)); } }
全部评论
(0) 回帖