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 ...
随机推荐
- iOS开发——新特性篇&swift新特性(__nullable和__nonnull)
swift新特性(__nullable和__nonnull) 最近在看老师写代码的时候经常遇到两个陌生的关键字,但是当我在我的电脑上敲得时候就是敲不出,后来才知道这是为了swift与OC混编的时候产生 ...
- PYTHON 源码阅读
http://www.wklken.me/posts/2015/09/29/python-source-gc.html http://www.wklken.me/archives.html https ...
- Lua调用自定义C++类
弄了一天终于会Lua调用自定义C++类.不容易啊. 我的电脑是64位的,装了64的Python不行,装了32位的就可以了,靠!下面是报错信息 python pyyaml Cheetah全都是装32位的 ...
- Hive官方手册翻译(Getting Started)(转)
原文:http://slaytanic.blog.51cto.com/2057708/939950 翻译Hive官方文档系列,文中括号中包含 注: 字样的,为我自行标注的,水平有限,翻译不是完美无缺的 ...
- 分布式ActiveMQ集群--转载
原文地址:http://shensy.iteye.com/blog/1752529 回顾总结前一段时间学习的ActiveMQ分布式集群相关的知识,分享出来希望对看到的人有所帮助. 一.分布式Activ ...
- MPEG简介 + 如何计算CBR 和VBR的MP3的播放时间
1. 声明本文所写内容,多数整理自互联网,版权归原作者所有笔者知识有限,文中难免有误,欢迎批评指正,admin (at) crifan.com觉得此文对你有帮助,想要发邮件来感谢的,也欢迎哈,^_^欢 ...
- Node.js module.exports和exports的区别
require 用来加载代码,而 exports 和 module.exports 则用来导出代码,从接触node.js就不会它们两陌生,上代码: foo.js exports.a = functio ...
- javaweb学习总结九(xml解析以及调整JVM内存大小)
一:解析XML文件的两种方式 1:dom,document object model,文档对象模型. 2:sax,simple API for XML. 3:比较dom和sax解析XML文件的优缺点 ...
- HDU 2295 Radar (DLX + 二分)
Radar Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- ZOJ 3209 Treasure Map (Dancing Links)
Treasure Map Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit S ...