Poj 2996 Help Me with the Game
1.Link:
http://poj.org/problem?id=2996
2.Content:
Help Me with the Game
Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3500 Accepted: 2245 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,h6Source
3.Method:
模拟题,输入输出麻烦,最好一部部增加格式,来调整,不然一开始考虑全部的话很容易混乱
4.Code:
#include <iostream>
#include <string>
#include <cstring> using namespace std; struct Point_c
{
char name;
char p_ch;
char p_num;
}; const char name_c[] = {'K','Q','R','R','B','B','N','N','P','P','P','P','P','P','P','P',
'k','q','r','r','b','b','n','n','p','p','p','p','p','p','p','p'};
const int num_c = ; int main()
{
//freopen("D://input.txt","r",stdin); int i,j,k;
char p_ch[num_c];
char p_num[num_c]; //cout << str << endl;
memset(p_ch,,sizeof(char) * num_c);
memset(p_num,,sizeof(char) * num_c); string *arr_str = new string[];
string str;
for(i = ; i < ; ++i)
{
cin >> str;
cin >> arr_str[i];
}
cin >> str; //for(i = 0; i < 8; ++i) cout << arr_str[i] << endl; for(i = ; i >= ; --i)
{
for(j = ; j < ; ++j)
{
for(k = ; k < ; ++k)
{
if(name_c[k] == arr_str[i][ + * j] && p_ch[k] == )
{
p_ch[k] = j + 'a';
p_num[k] = ( - i) + '';
break;
}
}
}
} for(i = ; i < ; ++i)
{
for(j = ; j < ; ++j)
{
for(k = ; k < ; ++k)
{
if(name_c[k] == arr_str[i][ + * j] && p_ch[k] == )
{
p_ch[k] = j + 'a';
p_num[k] = ( - i) + '';
break;
}
}
}
} int flag = ; cout << "White: ";
for(k = ; k < ; ++k) if(p_ch[k] != )
{
if(p_ch[k] != )
{
if(flag) cout << ",";
else flag = ;
cout << name_c[k] << p_ch[k] << p_num[k];
}
}
for(k = ; k < ; ++k)
{
if(p_ch[k] != )
{
if(flag) cout << ",";
else flag = ;
cout << p_ch[k] << p_num[k];
} }
cout << endl; flag = ;
cout << "Black: ";
for(k = ; k < ; ++k) if(p_ch[k] != )
{
if(p_ch[k] != )
{
if(flag) cout << ",";
else flag = ;
cout << (char)(name_c[k] + ('K' - 'k')) << p_ch[k] << p_num[k];
} }
for(k = ; k < ; ++k)
{
if(p_ch[k] != )
{
if(flag) cout << ",";
else flag = ;
cout << p_ch[k] << p_num[k];
}
}
cout << endl; delete [] arr_str; return ;
}
5.Reference:
Poj 2996 Help Me with the Game的更多相关文章
- 模拟 POJ 2996 Help Me with the Game
题目地址:http://poj.org/problem?id=2996 /* 题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子 模拟题 + 结构体排序:无算法,switch区分读入的字符,按 ...
- poj 2996 Help Me with the Game(模拟)
题目:http://poj.org/problem?id=2996 题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按 ...
- POJ 2996 & 2993 国际象棋布局 模拟
Description Your task is to read a picture of a chessboard position and print it in the chess notati ...
- 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0
Help Me with the Game Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3510 Accepted: ...
- poj 2996
提示:很烦很简单的国际象棋棋盘模拟,输入比较麻烦而已 输出时: 1.不论黑白,KQRBN P均是依次输出,强制大写,但不输出“P”,只输出其坐标 2.对白棋的位置,小行优先大行输出(行的数字越小则优先 ...
- POJ 2996:Help Me with the Game
Help Me with the Game Time Limit: 1000MS Memory Limit: 65536KB 64bit IO Format: %I64d & %I64 ...
- poj很好很有层次感(转)
OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...
- POJ题目分类推荐 (很好很有层次感)
著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299 ...
- poj 2993
跟poj 2996反过来了,这里比较麻烦的就是处理白棋和黑棋各棋子对应的位置 还有在最后打印棋盘式|,:,.的时候会有点繁琐(- - ACMer新手 ): 直接看代码吧: #include<cs ...
随机推荐
- delphi res 字符串资源
delphi res 字符串资源 (2011/12/10 19:19:36) //res 字符串资源 //rc 文件:StringTablebegin0 "AAAA"1 " ...
- Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子
Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子 procedure TForm1.Button1Click(Sender: TObject); ...
- 详解Android Handler的使用-别说你不懂handler
我们进行Android开发时,Handler可以说是使用非常频繁的一个概念,它的用处不言而喻.本文就详细介绍Handler的基本概念和用法. Handler的基本概念 Handler主 ...
- android开发之Fragment加载到一个Activity中
Fragments 是android3.0以后添加的.主要是为了方便android平板端的开发.方便适应不同大小的屏幕.此代码是为了最简单的Fragment的使用,往一个Activity中添加Frag ...
- onClick,onServerClick,onClientClick
<asp:button id=button1 runat=server test=button1 onclick=button1_onclick/> <input type=butt ...
- C# Tcp协议收发数据
运行这个程序前需要先关闭Windows防火墙,Win7系统关闭防火墙的方法是在控制面板的“控制面板\系统和安全\Windows 防火墙\自定义设置”路径中,将“家庭或工作(专用)网络位置设置”和“公用 ...
- OpenVPN中的几个和连接相关的Timer解析
在OpenVPN中存在几个计时器,这些计时器限制着OpenVPN的一些特定行为的最长持续时间,如果设置不好,就会带来莫名其妙的断线问题,然而如何设置这些计数器也没有一个通用的方案,特定情况下不能太大也 ...
- 小白日记29:kali渗透测试之Web渗透-扫描工具-Vega
WEB扫描工具-Vega 纯图形化界面,Java编写的开源web扫描器.两种工作模式:扫描模式和代理模式[主流扫描功能].用于爬站.处理表单,注入测试等.支持SSL:http://vega/ca.cr ...
- 小白日记6:kali渗透测试之被动信息收集(五)-Recon-ng
Recon-ng Recon-NG是由python编写的一个开源的Web侦查(信息收集)框架.Recon-ng框架是一个全特性的工具,使用它可以自动的收集信息和网络侦查.其命令格式与Metasploi ...
- Ubuntu中useradd和adduser的区别
在Ubuntu中创建新用户,通常会用到两个命令:useradd和adduser,虽然作用一样,但用法却不尽相同.本文接下来便为读者带来具体的解释. AD:51CTO学院:IT精品课程在线看! 在Ubu ...