Help Me with the Game(poj2996模拟)
来源:互联网 发布:无锡乐知英语 编辑:程序博客网 时间:2024/05/17 06:01
/*
http://poj.org/problem?id=2996
Help Me with the Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2841 Accepted: 1834
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.
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,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
Source
CTU Open 2005
解析:
题意:根据所给的棋盘,输出黑子和白子所放的位置
思路:利用map容器完成字母和下标的映射,用结构体存储,然后一行一行地枚举
*/
http://poj.org/problem?id=2996
Help Me with the Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 2841 Accepted: 1834
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.
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,e4
Black: Ke8,Qd8,Ra8,Rh8,Bc8,Ng8,Nc6,a7,b7,c7,d7,e7,f7,h7,h6
Source
CTU Open 2005
解析:
题意:根据所给的棋盘,输出黑子和白子所放的位置
思路:利用map容器完成字母和下标的映射,用结构体存储,然后一行一行地枚举
*/
#include<stdio.h>#include<string.h>#include<map>#include<algorithm>#include <iostream>using namespace std;const int maxn=100;char ty[10]="kqrbnp\0";char cl[15]="abcdefgh\0";char s1[40],s2[40];map<int,int>m1,m2;struct point{int t; int c; int r;}b[maxn],w[maxn];void init(){for(int i=0;i<6;i++)m2[ty[i]]=i;for(int i=0;i<6;i++)m1[ty[i]-32]=i;}bool cmp1(point p1,point p2){return (p1.t<p2.t)||(p1.t==p2.t&&p1.r<p2.r)||(p1.t==p2.t&&p1.r==p2.r&&p1.c<p2.c);}bool cmp2(point p1,point p2){return (p1.t<p2.t)||(p1.t==p2.t&&p1.r>p2.r)||(p1.t==p2.t&&p1.r==p2.r&&p1.c<p2.c);}int main(){ int i,j,k; char ch; int t1,t2; t1=t2=0; init(); for(i=8;i>=1;i--) {scanf("%s",s1); // printf("%s\n",s1); scanf("%s",s2); // printf("%s\n",s2); for(k=0;k<strlen(s2)-2;k+=4) { if((s2[k+1]==':'&&s2[k+2]!=':')||(s2[k+1]=='.'&&s2[k+2]!='.')) { if(s2[k+2]>='A'&&s2[k+2]<='Z') {w[t1].t=m1[s2[k+2]]; w[t1].c=k/4; w[t1].r=i; t1++; // } if(s2[k+2]<='z'&&s2[k+2]>='a') { b[t2].t=m2[s2[k+2]]; b[t2].c=k/4; b[t2].r=i; t2++; //printf("b=%c%d\n",cl[b[t2-1].c],b[t2-1].r); } } } } scanf("%s",s1); //printf("s1=%s\n",s1); sort(b,b+t2,cmp2); sort(w,w+t1,cmp1); printf("White: "); for(i=0;i<t1;i++) { if(w[i].t!=5) printf("%c",ty[w[i].t]-32); printf("%c%d",cl[w[i].c],w[i].r); if(i<t1-1) printf(","); } printf("\nBlack: "); for(i=0;i<t2;i++) { if(b[i].t!=5) printf("%c",ty[b[i].t]-32); printf("%c%d",cl[b[i].c],b[i].r); if(i<t2-1) printf(","); } printf("\n"); return 0;}
- 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
- 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(模拟)
- poj_2996 Help Me with the Game(模拟)
- POJ 2996Help Me with the Game(模拟)
- POJ 2996 Help Me with the Game(模拟)
- POJ 2996 Help Me with the Game(模拟)
- poj2996 Help Me with the Game 结构体多级排序 桶排序
- C++ string 详解
- Parencodings(poj1068简单模拟)
- hdu1754 I Hate It (线段树)
- H面试程序(1)编写一个函数,要求输入年月日时分秒,输出该年月日时分秒的 下一秒
- 标准C++中的string类的用法总结
- Help Me with the Game(poj2996模拟)
- error LNK2019: 无法解析的外部符号 "__declspec(dllimport) public: static void __cdecl xercesc_2_8::XMLPlatfor
- hdu 4405 Aeroplane chess
- 小憩于深圳 (一)
- Notes for teardown device
- spoj 4155 (LCT)
- 存储常见术语和概念
- Emag eht htiw Em Pleh(poj1999模拟)
- 欧拉回路