poj 2993 Emag eht htiw Em Pleh

Emag eht htiw Em Pleh
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 2312   Accepted: 1548

Description

This problem is a reverse case of the problem 2996. You are given the output of the problem H and your task is to find the corresponding input.

Input

according to output of problem 2996.

Output

according to input of problem 2996.

Sample Input

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

Sample Output

+---+---+---+---+---+---+---+---+
|.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.|
+---+---+---+---+---+---+---+---+

Source

#include<stdio.h>
#include<string.h>
char map[8][40]={"|...|:::|...|:::|...|:::|...|:::|",
                  "|:::|...|:::|...|:::|...|:::|...|",
                  "|...|:::|...|:::|...|:::|...|:::|",
                  "|:::|...|:::|...|:::|...|:::|...|",
                  "|...|:::|...|:::|...|:::|...|:::|",
                  "|:::|...|:::|...|:::|...|:::|...|",
                  "|...|:::|...|:::|...|:::|...|:::|",
                  "|:::|...|:::|...|:::|...|:::|...|",};
                  //先把棋盘的形状打出来,到时候只要更改相应位置就行了。
char str[40]={"+---+---+---+---+---+---+---+---+"};
char a[100];
char b[100000];
char c[100000];
int main()
{
     int i,j,k,lenb,lenc,x,y;
     memset(a,0,sizeof(a));
     memset(b,0,sizeof(b));
     memset(c,0,sizeof(c));
     gets(b);//白方
     lenb=strlen(b);
     gets(c);//黑方
     lenc=strlen(c);
     for(i=7;i<lenb;i++)
     {
          k=0;
         for(j=i;j<lenb;j++)//分离出每一个棋子
         {
              if(b[j]==',')
              break;
              else
              a[k++]=b[j];
         }
         i=j;
          if(k==3)//除卒子以外的棋子
          {
               x=8-(a[2]-'0');//化成行坐标
               y=a[1]-'a'+1;//化成纵坐标
               map[x][4*y-2]=a[0];//白方是大写
          }
          else if(k==2)
          {
               x=8-(a[1]-'0');//卒子
               y=a[0]-'a'+1;
          map[x][4*y-2]='P';//大写的P
          }

     }
     for(i=7;i<lenc;i++)//黑方
     {
          k=0;
         for(j=i;j<lenc;j++)//分离卒子
         {
              if(c[j]==',')
              break;
              else
              a[k++]=c[j];
         }
         i=j;
          if(k==3)
          {
               x=8-(a[2]-'0');
               y=a[1]-'a'+1;
               map[x][4*y-2]=a[0]+'a'-'A';//化成小写
          }
          else if(k==2)
          {
               x=8-(a[1]-'0');
               y=a[0]-'a'+1;
          map[x][4*y-2]='p';//小写的p
          }

     }
     for(i=0;i<8;i++)//输出棋盘
     {
           puts(str);
           puts(map[i]);

     }
     puts(str);

     return 0;
}
原文地址:https://www.cnblogs.com/llei1573/p/3224488.html