POJ2996,Help Me with the Game,棋盘模拟,同水且繁
来源:互联网 发布:公交大数据 编辑:程序博客网 时间:2024/06/04 18:11
Help Me with the Game
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.
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.
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
分析:
尼玛把黑白搞反了有木有啊!!!行号倒着来没发现有木有啊!!!
水题切了我N久。。。
code:
#include<iostream>#include<cstdlib>#include<cstdio>#include<cstring>#include<string>#include<cmath>#include<algorithm>using namespace std;char line[35],tmp;typedef struct piece{ int row; char col;}piece;piece K,k,Q,q,R[2],r[2],B[2],b[2],N[2],n[2],P[8],p[8];int nR,nr,nB,nb,nN,nn,nP,np;bool cmpw(piece a,piece b){if(a.row==b.row)return a.col<b.col;else return a.row<b.row;}bool cmpb(piece a,piece b){if(a.row==b.row)return a.col<b.col;else return a.row>b.row;}int main(){ int i,j; for(i=0;i<17;i++) { if(i%2==0) { gets(line); } else { for(j=0;j<33;j++) { if(j%4!=2) scanf("%c",&tmp); else { scanf("%c",&tmp); switch(tmp) { case 'K': K.row=8-i/2;K.col='a'+j/4;break; case 'k': k.row=8-i/2;k.col='a'+j/4;break; case 'Q': Q.row=8-i/2;Q.col='a'+j/4;break; case 'q': q.row=8-i/2;q.col='a'+j/4;break; case 'R': R[nR].row=8-i/2;R[nR].col='a'+j/4;nR++;break; case 'r': r[nr].row=8-i/2;r[nr].col='a'+j/4;nr++;break; case 'B': B[nB].row=8-i/2;B[nB].col='a'+j/4;nB++;break; case 'b': b[nb].row=8-i/2;b[nb].col='a'+j/4;nb++;break; case 'N': N[nN].row=8-i/2;N[nN].col='a'+j/4;nN++;break; case 'n': n[nn].row=8-i/2;n[nn].col='a'+j/4;nn++;break; case 'P': P[nP].row=8-i/2;P[nP].col='a'+j/4;nP++;break; case 'p': p[np].row=8-i/2;p[np].col='a'+j/4;np++;break; default: break; } } } getchar(); } }sort(R,R+nR,cmpw);sort(B,B+nB,cmpw);sort(N,N+nN,cmpw);sort(P,P+nP,cmpw);sort(r,r+nr,cmpb);sort(b,b+nb,cmpb);sort(n,n+nn,cmpb);sort(p,p+np,cmpb);printf("White: K%c%d,Q%c%d",K.col,K.row,Q.col,Q.row); for(i=0;i<nR;i++) printf(",R%c%d",R[i].col,R[i].row); for(i=0;i<nB;i++) printf(",B%c%d",B[i].col,B[i].row); for(i=0;i<nN;i++) printf(",N%c%d",N[i].col,N[i].row); for(i=0;i<nP;i++) printf(",%c%d",P[i].col,P[i].row); printf("\n"); printf("Black: K%c%d,Q%c%d",k.col,k.row,q.col,q.row); for(i=0;i<nr;i++) printf(",R%c%d",r[i].col,r[i].row); for(i=0;i<nb;i++) printf(",B%c%d",b[i].col,b[i].row); for(i=0;i<nn;i++) printf(",N%c%d",n[i].col,n[i].row); for(i=0;i<np;i++) printf(",%c%d",p[i].col,p[i].row); printf("\n"); return 0;}
- POJ2996,Help Me with the Game,棋盘模拟,同水且繁
- POJ2996《Help Me with the Game》方法:模拟
- Help Me with the Game(poj2996模拟)
- POJ2996--Help Me with the Game(模拟题)
- POJ2996 Help Me with the Game 模拟题
- POJ2996 Help Me with the Game(未完待续,模拟)
- poj2996 Help Me with the Game
- poj2996--Help Me with the Game
- POJ2996 - Help Me with the Game
- poj2996--Help Me with the Game
- Help Me with the Game(模拟法)
- 模拟 Help Me with the Game 2996
- POJ 2996-Help Me with the Game(模拟-描述棋盘中KQRBNP的位置)
- poj2996 Help Me with the Game 结构体多级排序 桶排序
- Help Me with the Game
- Help Me with the Game
- Help Me with the Game
- Help Me with the Game 恶心的模拟。
- Editplus做Python的开发环境
- Struts 2 <s:iterator>标签嵌套以及遍历双层List
- 我不能微笑的原谅自己,没有爱又能怎样:伤感心情日志
- 螺旋矩阵之第二篇
- S3C2440 SDRAM内存驱动 (SDRAM驱动程序在init.s文件)
- POJ2996,Help Me with the Game,棋盘模拟,同水且繁
- 半小时让你成为EXCEL高手
- 发现了Android RadioGroup的一个Bug
- 情断的伤感QQ心情日志:可曾知否,有个人在思念着你
- RGB转灰度图的几种算法
- sql-server2005数据库 → sql-server2000数据库 的转换
- 誓爱逝爱的伤感唯美QQ日志分享:分手之后可以重来吗?
- 用Struts2的拦截器验证用户是否登录
- TheadLocal类介绍(从Sping应用角度)