博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 2996 & 2993 国际象棋布局 模拟
阅读量:5890 次
发布时间:2019-06-19

本文共 6391 字,大约阅读时间需要 21 分钟。

Description

Your task is to read a picture of a chessboard position and print it in the chess notation.

Input

The input consists of an ASCII-art picture of a chessboard with chess pieces on positions described by the input. The pieces of the white player are shown in upper-case letters, while the black player's pieces are lower-case letters. The letters are one of "K" (King), "Q" (Queen), "R" (Rook), "B" (Bishop), "N" (Knight), or "P" (Pawn). The chessboard outline is made of plus ("+"), minus ("-"), and pipe ("|") characters. The black fields are filled with colons (":"), white fields with dots (".").

Output

The output consists of two lines. The first line consists of the string "White: ", followed by the description of positions of the pieces of the white player. The second line consists of the string "Black: ", followed by the description of positions of the pieces of the black player.
The description of the position of the pieces is a comma-separated list of terms describing the pieces of the appropriate player. The description of a piece consists of a single upper-case letter that denotes the type of the piece (except for pawns, for that this identifier is omitted). This letter is immediatelly followed by the position of the piece in the standard chess notation -- a lower-case letter between "a" and "h" that determines the column ("a" is the leftmost column in the input) and a single digit between 1 and 8 that determines the row (8 is the first row in the input).
The pieces in the description must appear in the following order: King("K"), Queens ("Q"), Rooks ("R"), Bishops ("B"), Knights ("N"), and pawns. Note that the numbers of pieces may differ from the initial position because of capturing the pieces and the promotions of pawns. In case two pieces of the same type appear in the input, the piece with the smaller row number must be described before the other one if the pieces are white, and the one with the larger row number must be described first if the pieces are black. If two pieces of the same type appear in the same row, the one with the smaller column letter must appear first.
poj2993:

Sample Input

White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6

Sample Output

+---+---+---+---+---+---+---+---+|.r.|:::|.b.|:q:|.k.|:::|.n.|:r:|+---+---+---+---+---+---+---+---+|:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.|+---+---+---+---+---+---+---+---+|...|:::|.n.|:::|...|:::|...|:p:|+---+---+---+---+---+---+---+---+|:::|...|:::|...|:::|...|:::|...|+---+---+---+---+---+---+---+---+|...|:::|...|:::|.P.|:::|...|:::|+---+---+---+---+---+---+---+---+|:P:|...|:::|...|:::|...|:::|...|+---+---+---+---+---+---+---+---+|.P.|:::|.P.|:P:|...|:P:|.P.|:P:|+---+---+---+---+---+---+---+---+|:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.|+---+---+---+---+---+---+---+---+
代码:
#include
#include
#include
using namespace std;char q[10],w[100];char e[10],r[100];char white[12]= {'K','Q','R','B','N','P'};char black[12]= {'k','q','r','b','n','p'};char map1[18][35];int s1,s2;int main(){ int i,j; for(i=1; i<=17; i++) //初始化地图 for(j=1; j<=33; j++) { if(i%2==1&&j%4==1) map1[i][j]='+'; else if(i%2==1) map1[i][j]='-'; else if(i%2==0&&j%4==1) map1[i][j]='|'; else if(i%4==2&&(double)(j%8)/4<=1&&j%8!=0) map1[i][j]='.'; else if(i%4==0&&((double)(j%8)/4>1||j%8==0)) map1[i][j]='.'; else map1[i][j]=':'; } for(int k=1; k<=2; k++) //两行输入 { scanf("%s%s",q,w); s1=strlen(w); if(q[0]=='W') { for(i=0; i<=5; i++) for(j=0; j<=s1; j++) { if(w[j]==white[i]) map1[2*(9-w[j+2]+'0')][4*(w[j+1]-'a')+3]=white[i]; if(w[j]==','&&w[j+1]>96) map1[2*(9-w[j+2]+'0')][4*(w[j+1]-'a')+3]='P'; } } if(q[0]=='B') { for(i=0; i<=5; i++) for(j=0; j<=s1; j++) { if(w[j]==white[i]) map1[2*(9-w[j+2]+'0')][4*(w[j+1]-'a')+3]=black[i]; if(w[j]==','&&w[j+1]>96) map1[2*(9-w[j+2]+'0')][4*(w[j+1]-'a')+3]='p'; } } } for(i=1; i<=17; i++) { for(j=1; j<=33; j++) cout<
poj2996:

Sample Input

+---+---+---+---+---+---+---+---+|.r.|:::|.b.|:q:|.k.|:::|.n.|:r:|+---+---+---+---+---+---+---+---+|:p:|.p.|:p:|.p.|:p:|.p.|:::|.p.|+---+---+---+---+---+---+---+---+|...|:::|.n.|:::|...|:::|...|:p:|+---+---+---+---+---+---+---+---+|:::|...|:::|...|:::|...|:::|...|+---+---+---+---+---+---+---+---+|...|:::|...|:::|.P.|:::|...|:::|+---+---+---+---+---+---+---+---+|:P:|...|:::|...|:::|...|:::|...|+---+---+---+---+---+---+---+---+|.P.|:::|.P.|:P:|...|:P:|.P.|:P:|+---+---+---+---+---+---+---+---+|:R:|.N.|:B:|.Q.|:K:|.B.|:::|.R.|+---+---+---+---+---+---+---+---+

Sample Output

White: Ke1,Qd1,Ra1,Rh1,Bc1,Bf1,Nb1,a2,c2,d2,f2,g2,h2,a3,e4Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
代码:
#include
#include
using namespace std;char black[6]= {'K','Q','R','B','N','P'};char white[6]= {'k','q','r','b','n','p'};int main(){ int s1,s2; int i,j,k; char map1[18][34]; s1=s2=0; for(i=1; i<=17; i++) for(j=1; j<=33; j++) { cin>>map1[i][j]; if(map1[i][j]=='p') //这个是为了不输出最后的那个逗号。。

。 s1++; if(map1[i][j]=='P') s2++; } cout<<"White: "; for(k=0; k<6; k++) for(i=17; i>=1; i--) for(j=1; j<=33; j++) { if(i%2==0&&j%4==3&&k<=4) if(map1[i][j]==black[k]) { printf("%c%c%d,",black[k],'a'+(j+1)/4-1,9-i/2); } if(k==5&&i%2==0&&j%4==3) if(map1[i][j]=='P') { s1--; if(s1==0) { printf("%c%d\n",'a'+(j+1)/4-1,9-i/2); continue; } printf("%c%d,",'a'+(j+1)/4-1,9-i/2); } } cout<<"Black: "; for(k=0; k<6; k++) for(i=1; i<=17; i++) for(j=1; j<=33; j++) { if(i%2==0&&j%4==3&&k<=4) if(map1[i][j]==white[k]) { printf("%c%c%d,",black[k],'a'+(j+1)/4-1,9-i/2); } if(k==5&&i%2==0&&j%4==3) if(map1[i][j]=='p') { s2--; if(s2==0) { printf("%c%d\n",'a'+(j+1)/4-1,9-i/2); continue; } printf("%c%d,",'a'+(j+1)/4-1,9-i/2); } } return 0; }

基本渣 这样的模拟题只能用时间来堆TAT

转载地址:http://jbfsx.baihongyu.com/

你可能感兴趣的文章
odoo 负载均衡
查看>>
tigerVNC 使用简介
查看>>
GCD
查看>>
科大讯飞 语言听写去掉标点 iOS
查看>>
Mybatis 学习笔记四 MyBatis-Plus插件
查看>>
Beanstalkd一个高性能分布式内存队列系统
查看>>
Mac操作技巧
查看>>
DedeCms V5.6 本地包含里的上传漏洞(可是那包含漏洞已经公布)
查看>>
Iframe子页面链接控制整个页面的跳转的方法
查看>>
pom.xml详解
查看>>
OSPF的七种状态机
查看>>
centos下安装rar及rar命令大全
查看>>
替换IP4种方法
查看>>
nginx 配置多虚拟主机需要注意事项
查看>>
Facebook员工三年的经验
查看>>
Struts 2中的OGNL
查看>>
PHP页面跳转几种实现技巧
查看>>
vue-cli-element-ui-scss-axios
查看>>
跨数据库查询:MySQL inner join PostgreSQL inner join ...
查看>>
IOS 距离现在的几分,几个小时,几分钟,几天,几周几月,几年
查看>>