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

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

#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
char map[10][10];
char str[10]="KQRBNP";
void pri(int i,char c,int &first){
if(i==1){
for(int i=8;i>=1;i--){
for(int j=1;j<=8;j++){
if(map[i][j]==c){
if(!first)
first=1;
else
printf(",");
if(c!='P')
printf("%c",c);
printf("%c%d",'a'+j-1,9-i);
}
}
}
}
else if(i==0){
for(int i=1;i<=8;i++){
for(int j=1;j<=8;j++){
if(map[i][j]==c+32){
if(!first)
first=1;
else
printf(",");
if(c!='P')
printf("%c",c);
printf("%c%d",'a'+j-1,9-i);
}
}
}
}
}
void getanswer(int i){
if(i==1)
printf("White: ");
else if(i==0)
printf("Black: ");
int first=0;
for(int k=0;k<=5;k++){
pri(i,str[k],first);
}
}
void getline(){
scanf("+---+---+---+---+---+---+---+---+") ;
getchar();
}
char getcase(){
char a,b,c;
scanf("|%c%c%c",&a,&b,&c);
return b ;
}
int main(){

for(int i=1;i<=8;i++){
getline();
for(int j=1;j<=8;j++){
char temp=getcase();
map[i][j]=temp;
}
getchar();
getchar();
}
getline();
getanswer(1);
cout<<endl;
getanswer(0);

cout<<endl;

return 0;
}

poj2996 模拟的更多相关文章

  1. POJ2996 Help Me with the Game(模拟)

    题目链接. 分析: 简单模拟. #include <iostream> #include <queue> #include <cstdio> #include &l ...

  2. 模拟 POJ 2993 Emag eht htiw Em Pleh

    题目地址:http://poj.org/problem?id=2993 /* 题意:与POJ2996完全相反 模拟题 + 字符串处理:无算法,读入两行字符串找出相应点用used标记,输出时标记过的输出 ...

  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---模拟棋子

    题目链接: https://vjudge.net/problem/POJ-2996 题目大意: 给出白方和黑方的棋子和对应的坐标,输出该副棋盘的样子 1,棋盘中大写字母表示的是白方棋子,小写是黑方.2 ...

  5. App开发:模拟服务器数据接口 - MockApi

    为了方便app开发过程中,不受服务器接口的限制,便于客户端功能的快速测试,可以在客户端实现一个模拟服务器数据接口的MockApi模块.本篇文章就尝试为使用gradle的android项目设计实现Moc ...

  6. 故障重现, JAVA进程内存不够时突然挂掉模拟

    背景,服务器上的一个JAVA服务进程突然挂掉,查看产生了崩溃日志,如下: # Set larger code cache with -XX:ReservedCodeCacheSize= # This ...

  7. Python 爬虫模拟登陆知乎

    在之前写过一篇使用python爬虫爬取电影天堂资源的博客,重点是如何解析页面和提高爬虫的效率.由于电影天堂上的资源获取权限是所有人都一样的,所以不需要进行登录验证操作,写完那篇文章后又花了些时间研究了 ...

  8. HTML 事件(四) 模拟事件操作

    本篇主要介绍HTML DOM中事件的模拟操作. 其他事件文章 1. HTML 事件(一) 事件的介绍 2. HTML 事件(二) 事件的注册与注销 3. HTML 事件(三) 事件流与事件委托 4.  ...

  9. 模拟AngularJS之依赖注入

    一.概述 AngularJS有一经典之处就是依赖注入,对于什么是依赖注入,熟悉spring的同学应该都非常了解了,但,对于前端而言,还是比较新颖的. 依赖注入,简而言之,就是解除硬编码,达到解偶的目的 ...

随机推荐

  1. C#基础知识系列四(运算符汇总)

    前言  本节主要来讲C#中的各种运算符.主要包括is运算符.as运算符.checked和unchecked运算符.sizeof运算符.空接合运算符(??).&和&&.移位运算符 ...

  2. 编写高质量代码改善C#程序的157个建议[勿选List<T>做基类、迭代器是只读的、慎用集合可写属性]

    前言 本文已更新至http://www.cnblogs.com/aehyok/p/3624579.html .本文主要学习记录以下内容: 建议23.避免将List<T>作为自定义集合类的基 ...

  3. Win7 下以管理员身份运行批处理文件,切换JDK版本

    Win7下 切换JDK的批处理命令 1. 批处理文件(必须以管理员身份执行)内容如下 @echo off rem --- Base Config 配置JDK的安装目录 --- :init set JA ...

  4. [转]Java中的private、protected、public和default的区别

    原文地址:http://my.oschina.net/u/1169535/blog/403589 (1)对于public修饰符,它具有最大的访问权限,可以访问任何一个在CLASSPATH下的类.接口. ...

  5. JS弹出窗口代码大全(详细整理)

    1.弹启一个全屏窗口 复制代码代码如下: <html> <body http://www.jb51.net','脚本之家','fullscreen');">; < ...

  6. MySQL tips (日期时间操作/concat 等)

    1.  Query结尾要加一个分号: 2.  数据库和表 SHOW DATABASES;    USE YOUR_DB; SHOW TABLES; SHOW COLUMNS FROM study或者D ...

  7. 11.Android之常用对话框AlertDialog学习

    (1)首先我们写个简单的AlertDialog对话框,要创建一个AlertDialog,就要用到AlertDialog.Builder中的create()方法,然后创建对话框可以设置对话框的属性,比如 ...

  8. 点击div区域以外部分,div区域隐藏

    核心思想: 监听body的click事件,事件触发的时候判断是否发生在弹出的div上,如果不在,关闭弹层 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTM ...

  9. groovy-位运算

    从Groovy 1.0 beta 10开始,Groovy支持位运算:<<. >>, >>>, |, &, ^, and ~. 下表列出了位运算的操作符 ...

  10. appium跑demo简单实例讲解

    安装appium,设置 demo.pyfrom appium import webdriver #要装webdriver,方法查看http://www.cnblogs.com/sincoolvip/p ...