POJ 2993:Emag eht htiw Em Pleh

Time Limit: 1000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u

 Status

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

题意就是把2996的那道题的输出变输入,输入变输出。我觉得一下子变简单了很多,起码没那么多的麻烦事了。

思路就是现在是一个空棋盘,然后题目给了各个棋子的位置,拿这些棋子去占相应的位置,之后再输出占好各个位置的棋盘。

代码:

#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std;

const string temp="+---+---+---+---+---+---+---+---+";
string test[20];
string cal[5];

int i,len;
char row,col;

int main()
{
	test[1]="|...|:::|...|:::|...|:::|...|:::|";
	test[2]="|:::|...|:::|...|:::|...|:::|...|";
	test[3]="|...|:::|...|:::|...|:::|...|:::|";
	test[4]="|:::|...|:::|...|:::|...|:::|...|";
	test[5]="|...|:::|...|:::|...|:::|...|:::|";
	test[6]="|:::|...|:::|...|:::|...|:::|...|";
	test[7]="|...|:::|...|:::|...|:::|...|:::|";
	test[8]="|:::|...|:::|...|:::|...|:::|...|";
	
	cin>>cal[0];
	cin>>cal[1];
	cin>>cal[3];
	cin>>cal[2];

	len=cal[1].length();
	for(i=0;i<len;i++)
	{
		if(cal[1][i]==',')continue;
		else if(cal[1][i]=='K')
		{
			row=cal[1][i+1];
			col=cal[1][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='K';
			i=i+2;
		}
		else if(cal[1][i]=='Q')
		{
			row=cal[1][i+1];
			col=cal[1][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='Q';
			i=i+2;
		}
		else if(cal[1][i]=='R')
		{
			row=cal[1][i+1];
			col=cal[1][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='R';
			i=i+2;
		}
		else if(cal[1][i]=='B')
		{
			row=cal[1][i+1];
			col=cal[1][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='B';
			i=i+2;
		}
		else if(cal[1][i]=='N')
		{
			row=cal[1][i+1];
			col=cal[1][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='N';
			i=i+2;
		}
		else if(cal[1][i]>='a'&&cal[1][i]<='h')
		{
			row=cal[1][i];
			col=cal[1][i+1];

			test[9-(col-'0')][(row-'a')*4+2]='P';
			i=i+1;
		}
	}

	len=cal[2].length();
	for(i=0;i<len;i++)
	{
		if(cal[2][i]==',')continue;
		else if(cal[2][i]=='K')
		{
			row=cal[2][i+1];
			col=cal[2][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='k';
			i=i+2;
		}
		else if(cal[2][i]=='Q')
		{
			row=cal[2][i+1];
			col=cal[2][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='q';
			i=i+2;
		}
		else if(cal[2][i]=='R')
		{
			row=cal[2][i+1];
			col=cal[2][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='r';
			i=i+2;
		}
		else if(cal[2][i]=='B')
		{
			row=cal[2][i+1];
			col=cal[2][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='b';
			i=i+2;
		}
		else if(cal[2][i]=='N')
		{
			row=cal[2][i+1];
			col=cal[2][i+2];

			test[9-(col-'0')][(row-'a')*4+2]='n';
			i=i+2;
		}
		else if(cal[2][i]>='a'&&cal[2][i]<='h')
		{
			row=cal[2][i];
			col=cal[2][i+1];

			test[9-(col-'0')][(row-'a')*4+2]='p';
			i=i+1;
		}
	}

	cout<<temp<<endl;
	for(i=1;i<=8;i++)
	{
		cout<<test[i]<<endl;
		cout<<temp<<endl;
	}

	return 0;
}


版权声明:本文为博主原创文章,未经博主允许不得转载。

原文地址:https://www.cnblogs.com/lightspeedsmallson/p/4785826.html