1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
| import java.util.HashMap; import java.util.Map; import java.util.Scanner;
public class Application {
static Map<String,String> map = new HashMap<>();
public static void view() {
map.put("(1,1)", "4U");map.put("(1,2)", "2R");map.put("(1,3)", "2R");map.put("(1,4)", "2D");map.put("(1,5)", "2D");
map.put("(2,1)", "3U");map.put("(2,2)", "1U");map.put("(2,3)", "2U");map.put("(2,4)", "1R");map.put("(2,5)", "2R");
map.put("(3,1)", "2L");map.put("(3,2)", "2R");map.put("(3,3)", "0");map.put("(3,4)", "2R");map.put("(3,5)", "4D");
map.put("(4,1)", "2L");map.put("(4,2)", "2L");map.put("(4,3)", "2D");map.put("(4,4)", "3L");map.put("(4,5)", "1D");
map.put("(5,1)", "4U");map.put("(5,2)", "1U");map.put("(5,3)", "1L");map.put("(5,4)", "3D");map.put("(5,5)", "2L");
System.out.println(map.get("(1,5)")+"\t"+map.get("(2,5)")+"\t"+map.get("(3,5)")+"\t"+map.get("(4,5)")+"\t"+map.get("(5,5)")); System.out.println(map.get("(1,4)")+"\t"+map.get("(2,4)")+"\t"+map.get("(3,4)")+"\t"+map.get("(4,4)")+"\t"+map.get("(5,4)")); System.out.println(map.get("(1,3)")+"\t"+map.get("(2,3)")+"\t"+map.get("(3,3)")+"\t"+map.get("(4,3)")+"\t"+map.get("(5,3)")); System.out.println(map.get("(1,2)")+"\t"+map.get("(2,2)")+"\t"+map.get("(3,2)")+"\t"+map.get("(4,2)")+"\t"+map.get("(5,2)")); System.out.println(map.get("(1,1)")+"\t"+map.get("(2,1)")+"\t"+map.get("(3,1)")+"\t"+map.get("(4,1)")+"\t"+map.get("(5,1)"));
}
public static void main(String[] args) { while(true) {
view();
System.out.println("请指定起始坐标"); System.out.println("示例:(1,2)"); System.out.print("> ");
Scanner sc = new Scanner(System.in); String point = sc.next(); String begin = point;
boolean key = false;
for(int i = 0; i < 999; i++) {
System.out.println("调试:"+point);
if(map.get(point).equals("0")) { key = true; break; }
int before = Integer.parseInt(map.get(point).charAt(0)+""); String after = map.get(point).charAt(1)+"";
if (after.equals("U")) { point = goUp(point,before); } else if (after.equals("D")) { point = goDown(point,before); } else if (after.equals("L")) { point = goLeft(point,before); } else if (after.equals("R")) { point = goRight(point,before); }
}
System.out.println("======"); if(key) { System.out.println("找树成功"); System.out.println("当前起始值为:"+begin); } else { System.out.println("找树失败"); } System.out.println("======");
System.out.println("输入任意值继续..."); String p = sc.next();
} }
public static String goUp(String c, int n) { int row = Integer.parseInt(c.charAt(1)+""); int col = Integer.parseInt(c.charAt(3)+""); for (int i = 0; i < n; i++) { col++; } return "("+row+","+col+")"; } public static String goDown(String c, int n) { int row = Integer.parseInt(c.charAt(1)+""); int col = Integer.parseInt(c.charAt(3)+""); for (int i = 0; i < n; i++) { col--; } return "("+row+","+col+")"; } public static String goLeft(String c, int n) { int row = Integer.parseInt(c.charAt(1)+""); int col = Integer.parseInt(c.charAt(3)+""); for (int i = 0; i < n; i++) { row--; } return "("+row+","+col+")"; } public static String goRight(String c, int n) { int row = Integer.parseInt(c.charAt(1)+""); int col = Integer.parseInt(c.charAt(3)+""); for (int i = 0; i < n; i++) { row++; } return "("+row+","+col+")"; }
}
|