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,h6

Source

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的更多相关文章

  1. 模拟 POJ 2996 Help Me with the Game

    题目地址:http://poj.org/problem?id=2996 /* 题意:给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子 模拟题 + 结构体排序:无算法,switch区分读入的字符,按 ...

  2. poj 2996 Help Me with the Game(模拟)

    题目:http://poj.org/problem?id=2996 题意:给出 棋盘 情况 输出 白棋 和 黑棋在 棋盘上的 白棋为大写字母 黑棋为小写字母 棋盘 左下点为原点(1,a) 输出 是 按 ...

  3. POJ 2996 &amp; 2993 国际象棋布局 模拟

    Description Your task is to read a picture of a chessboard position and print it in the chess notati ...

  4. 快速切题 poj 2996 Help Me with the Game 棋盘 模拟 暴力 难度:0

    Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3510   Accepted:  ...

  5. poj 2996

    提示:很烦很简单的国际象棋棋盘模拟,输入比较麻烦而已 输出时: 1.不论黑白,KQRBN P均是依次输出,强制大写,但不输出“P”,只输出其坐标 2.对白棋的位置,小行优先大行输出(行的数字越小则优先 ...

  6. POJ 2996:Help Me with the Game

    Help Me with the Game Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64 ...

  7. poj很好很有层次感(转)

    OJ上的一些水题(可用来练手和增加自信) (POJ 3299,POJ 2159,POJ 2739,POJ 1083,POJ 2262,POJ 1503,POJ 3006,POJ 2255,POJ 30 ...

  8. POJ题目分类推荐 (很好很有层次感)

    著名题单,最初来源不详.直接来源:http://blog.csdn.net/a1dark/article/details/11714009 OJ上的一些水题(可用来练手和增加自信) (POJ 3299 ...

  9. poj 2993

    跟poj 2996反过来了,这里比较麻烦的就是处理白棋和黑棋各棋子对应的位置 还有在最后打印棋盘式|,:,.的时候会有点繁琐(- - ACMer新手 ): 直接看代码吧: #include<cs ...

随机推荐

  1. Android源码编译的全过程记录

    写本篇文章主要参考了官方文档和网上的一些资料,但是对于Android最新的代码来说,网上资料有些已经过时.本文中步骤已经作者实验,大家可以亲自执行试试.由于没有使用Eclipse的习惯,所以没有做Ec ...

  2. 【Android】利用服务Service创建标题栏通知

    创建标题栏通知的核心代码 public void CreateInform() { //定义一个PendingIntent,当用户点击通知时,跳转到某个Activity(也可以发送广播等) Inten ...

  3. android140 360 黑名单 启动service和分页加载

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout ...

  4. C++编程对缓冲区的理解

    本文转自:http://www.vckbase.com/index.php/wv/1592 什么是缓冲区 缓冲区又称为缓存,它是内存空间的一部分.也就是说,在内存空间中预留了一定的存储空间,这些存储空 ...

  5. restful php

    http://bbs.phpchina.com/thread-228725-1-1.html http://www.cnblogs.com/artech/p/3506553.html http://w ...

  6. 小白日记15:kali渗透测试之弱点扫描-漏扫三招、漏洞管理、CVE、CVSS、NVD

    发现漏洞 弱点发现方法: 1.基于端口服务扫描结果版本信息,比对其是否为最新版本,若不是则去其 官网查看其补丁列表,然后去逐个尝试,但是此法弊端很大,因为各种端口应用比较多,造成耗时大. 2.搜索已公 ...

  7. javaEE学习笔记-利用DOM4J解析xml至数据库

    xml代码文件名:test02.xml <ACCESOS> <item> <SOCIO> <NUMERO>00045050</NUMERO> ...

  8. mongoDB操作命令及mongoDB的helper

    此项目已开源,开源地址是: http://mongodbhelper-csharp.googlecode.com/svn/trunk/ mongodb的helper using System; usi ...

  9. 练习题之ExChange

    两个线程可以交换对象的同步点.每个线程都在进入exChange方法时给出某个对象,并接受其他线程返回时给出的对象.用于实现两个人之间的数据交换,每个人在完成一定的事务后想与对方交换数据,第一个先拿出数 ...

  10. PHP中的Trait

    Trait 自 PHP 5.4.0 起,PHP 实现了一种代码复用的方法,称为 trait. Trait 是为类似 PHP 的单继承语言而准备的一种代码复用机制.Trait 为了减少单继承语言的限制, ...