盘棋析解之”Emag eht htiw Em Pleh“

题目大意:

  输入两行字符串代表棋子位置。

  打印棋盘。

  跟  解析棋盘之“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 }                            

 

转载于:https://www.cnblogs.com/love-fromAtoZ/p/7551904.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值