poj 2996 Help Me with the Game
来源:互联网 发布:彩票预测软件下载 编辑:程序博客网 时间:2024/05/05 12:46
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
#include <iostream>#include <cstdio>#include <cstring>#include <cstdlib>#include <queue>#include <stack>#include <algorithm>#define INF 0x3f3f3f3f#define LL long longusing namespace std;struct node{ int x,y; int d; char ch;} w[64],b[64];int Post(char ch){ if(ch == 'K' || ch == 'k') return 1; else if(ch == 'Q' || ch == 'q') return 2; else if(ch == 'R' || ch == 'r') return 3; else if(ch == 'B' || ch == 'b') return 4; else if(ch == 'N' || ch == 'n') return 5; else return 6;}bool cmp1(node a,node b){ if(a.d != b.d) return a.d < b.d; if(a.x != b.x) return a.x < b.x; return a.y < b.y;}bool cmp2(node a,node b){ if(a.d != b.d) return a.d < b.d; if(a.x != b.x) return a.x > b.x; return a.y < b.y;}int main(){ //freopen("in.txt","r",stdin); char a1,b1,c1,d1; int top_w = 0; int top_b = 0; char str[65]; for(int i=8; i>=1; i--) { cin>>str; for(int j=0; j<8; j++) { cin>>a1>>b1>>c1>>d1; if(c1=='.' || c1==':') continue; if(c1 >= 'A' && c1 <= 'Z') { b[top_b].x = i; b[top_b].y = j; b[top_b].d = Post(c1); b[top_b].ch = c1; top_b++; } else { w[top_w].x = i; w[top_w].y = j; w[top_w].d = Post(c1); w[top_w].ch = c1 - 32; top_w++; } } getchar(); } cin>>str; sort(b,b+top_b,cmp1); sort(w,w+top_w,cmp2); cout<<"White: "; for(int i=0; i<top_b; i++) { if(i) printf(","); if(b[i].ch != 'P') printf("%c%c%d",b[i].ch,b[i].y+'a',b[i].x); else printf("%c%d",b[i].y+'a',b[i].x); } printf("\n"); cout<<"Black: "; for(int i=0; i<top_w; i++) { if(i) printf(","); if(w[i].ch != 'P') printf("%c%c%d",w[i].ch,w[i].y+'a',w[i].x); else printf("%c%d",w[i].y+'a',w[i].x); } printf("\n"); return 0;}
0 0
- Poj 2996 Help Me with the Game
- POJ 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- POJ 2996 Help Me with the Game
- POJ 2996 Help Me with the Game
- POJ 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- poj-2996 Help Me with the Game
- POJ 2996 Help Me with the Game
- Poj 2996 Help Me with the Game
- POJ 2996:Help Me with the Game
- Help Me with the Game(POJ--2996
- poj 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- poj 2996 Help Me with the Game
- POJ-2996-Help Me with the Game
- poj 2996 Help Me with the Game
- c++中的三种排序,比较基础,因为作为一个编程员总要会几种排序方法
- Apache OFbiz entity engine源码解读
- 字符串匹配的KMP算法
- excel的几个好用快捷键
- tableView- 性能优化,cell的循环利用三种方式
- poj 2996 Help Me with the Game
- JAVA中String与StringBuffer,StringBuilder的区别
- 查找练习 hash——出现过的数字
- 用MATLAB画误差对比图
- leetcode 95: Unique Binary Search Trees II
- C#高级编程----第一部分完结
- 用过滤器让全站html标签转义输出
- UIImageView 和UIButton
- POJ 2155 Matrix