POJ 2993

Emag eht htiw Em Pleh

Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 4115   Accepted: 2637

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

CTU Open 2005

 

代码:

//poj2993 poj2996 的逆向题目 
#include <iostream>
#include <string>
using namespace std;
char c[17][33];
bool first(int k)
{
	if(k == 1 || k == 5 || k == 9 || k == 13)
		return true;
	return false;
}
void init(int myRow, int myCol)
{
	for(int i = 0; i < myRow; i++)
	{
		for(int j = 0; j < myCol; j++)
		{
			if(i % 2 == 0)
			{
				for(int k = 0; k < myCol; k++)
				{
					if(k % 4 == 0)
						c[i][k] = '+';
					else 
						c[i][k] = '-';
				}
				break;
			}
			else
			{
				if(first(i)) //白黑 
				{
					for(int k = 0; k < myCol; k++)
					{
						if(k % 4 == 0)
							c[i][k] = '|';
						else
						{
							if(k % 8 < 4)
							{
								c[i][k] = '.';
							}
							else
							{
								c[i][k] = ':';
							}
						}
					}
					break;
				}
				else //黑白 
				{
					for(int k = 0; k < myCol; k++)
					{
						if(k % 4 == 0)
							c[i][k] = '|';
						else
						{
							if(k % 8 > 4)
							{
								c[i][k] = '.';
							}
							else
							{
								c[i][k] = ':';
							}
						}
					}
					break;
				}
			}
		}
	}
}
bool role(char cc)
{
	if(cc == 'K' || cc == 'Q' || cc == 'R' || cc == 'B' || cc == 'N')
		return true;
	return false;
}
void deal(int myRow, int myCol)
{
	string b;
	getline(cin, b); //白 
	string a;
	getline(cin, a); //黑 
	int k = 0;
	while(b[k++] != 'K');
	int m = k - 1;
	while(m < b.length())
	{
		if(role(b[m]))
		{
			int col = (b[m + 1] - 'a') * 4 + 2;
			int row = 15 - (int(b[m + 2] - '0') - 1 ) * 2; 
			switch(b[m])
			{		
			case 'K':	
				c[row][col] = 'K';
				break;
			case 'Q':
				c[row][col] = 'Q'; 
				break;
			case 'R':
				c[row][col] = 'R'; 
				break;
			case 'B':
				c[row][col] = 'B'; 
				break;
			case 'N':
				c[row][col] = 'N'; 
				break;
			}
			m += 4;
		}
		else
		{
			int col = col = (b[m] - 'a') * 4 + 2;
			int row = 15 - (int(b[m + 1] - '0') - 1 ) * 2; 
			c[row][col] = 'P';
			m += 3;	
		}
	}
	//	getline(cin, b);
	k = 0;
	while(a[k++] != 'K');
	m  = k - 1;
	while(m < a.length())
	{
		if(role(a[m]))
		{
			int col = (a[m + 1] - 'a') * 4 + 2;
			int row = 15 - (int(a[m + 2] - '0') - 1 ) * 2; 
			switch(a[m])
			{		
			case 'K':	
				c[row][col] = 'k';
				break;
			case 'Q':
				c[row][col] = 'q'; 
				break;
			case 'R':
				c[row][col] = 'r'; 
				break;
			case 'B':
				c[row][col] = 'b'; 
				break;
			case 'N':
				c[row][col] = 'n'; 
				break;
			}
			m += 4;
		}
		else
		{
			int col = col = (a[m] - 'a') * 4 + 2;
			int row = 15 - (int(a[m + 1] - '0') - 1 ) * 2; 
			c[row][col] = 'p';
			m += 3;	
		}
	}
}
void print(int myRow, int myCol)
{
	for(int i = 0; i < myRow; i++)
	{
		for(int j = 0; j < myCol; j++)
		{
			cout<<c[i][j];
		}
		cout<<endl;
	}		
}
int main()
{
	int myRow = 17;
	int myCol = 33;
	init(myRow, myCol);
	deal(myRow, myCol);
	print(myRow, myCol);
	return 0;	
}

猜你喜欢

转载自blog.csdn.net/qq_40421671/article/details/82793830
POJ