题目大意:
输入两行字符串代表棋子位置。
打印棋盘。
跟 解析棋盘之“Help Me with the Game” 正好相反。
样例:
White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
————————————————————————————
解题思路:
模拟大法好。
还是要注意坑爹的坐标。
还要注意字符串的处理。
AC代码:
1 import java.util.*; 2 3 public class POJ2993{ 4 5 static String Map[] = { 6 "+---+---+---+---+---+---+---+---+" , 7 "|...|:::|...|:::|...|:::|...|:::|" , 8 "+---+---+---+---+---+---+---+---+" , 9 "|:::|...|:::|...|:::|...|:::|...|" , 10 "+---+---+---+---+---+---+---+---+" , 11 "|...|:::|...|:::|...|:::|...|:::|" , 12 "+---+---+---+---+---+---+---+---+" , 13 "|:::|...|:::|...|:::|...|:::|...|" , 14 "+---+---+---+---+---+---+---+---+" , 15 "|...|:::|...|:::|...|:::|...|:::|" , 16 "+---+---+---+---+---+---+---+---+" , 17 "|:::|...|:::|...|:::|...|:::|...|" , 18 "+---+---+---+---+---+---+---+---+" , 19 "|...|:::|...|:::|...|:::|...|:::|" , 20 "+---+---+---+---+---+---+---+---+" , 21 "|:::|...|:::|...|:::|...|:::|...|" , 22 "+---+---+---+---+---+---+---+---+" }; 23 24 static char map[][] = new char[20][40]; 25 26 static int set_x(char t){ 27 int out = 7 - (t - '1'); 28 out = 2 * out + 1; 29 return out; 30 } 31 32 static int set_y(char t){ 33 int out = t - 'a'; 34 out = 4 * out + 2; 35 return out; 36 } 37 38 public static void main(String[] args){ 39 Scanner sc = new Scanner(System.in); 40 while(sc.hasNext()){ 41 String w = sc.nextLine(); 42 String b = sc.nextLine(); 43 for(int i = 0;i <= 16;i ++){ 44 map[i] = Map[i].toCharArray(); 45 } 46 47 int i; int j; 48 49 for(i = 7; ; ){ 50 if(w.charAt(i) <= 'Z' && w.charAt(i) >= 'A'){ 51 int x = set_x(w.charAt(i + 2)); 52 int y = set_y(w.charAt(i + 1)); 53 map[x][y] = w.charAt(i); 54 i = i + 4; 55 } 56 else{break;} 57 }//System.out.println(i); 58 for(j = i;j < w.length(); ){ 59 if(w.charAt(j) <= 'z' && w.charAt(j) >= 'a'){ 60 int x = set_x(w.charAt(j + 1)); 61 int y = set_y(w.charAt(j)); 62 map[x][y] = 'P'; 63 j = j + 3; 64 } 65 else{break;} 66 } 67 68 for(i = 7; ; ){ 69 if(b.charAt(i) <= 'Z' && b.charAt(i) >= 'A'){ 70 int x = set_x(b.charAt(i + 2)); 71 int y = set_y(b.charAt(i + 1)); 72 map[x][y] = (char)(b.charAt(i) + 32); 73 i = i + 4; 74 } 75 else{break;} 76 } 77 for(j = i;j < b.length(); ){ 78 if(b.charAt(j) <= 'z' && b.charAt(j) >= 'a'){ 79 int x = set_x(b.charAt(j + 1)); 80 int y = set_y(b.charAt(j)); 81 map[x][y] = 'p'; 82 j = j + 3; 83 } 84 else{break;} 85 } 86 87 for(i = 0;i < 17;i ++){ 88 System.out.println(map[i]); 89 } 90 91 } 92 } 93 }