POJ 2993【Emag eht htiw Em Pleh】

13 篇文章 0 订阅
10 篇文章 0 订阅

题目链接

思路:

  • 如果之前写的Help Me with the Game(Blog) 是一道一题,那么 “Emag eht htiw Em Pleh” 恐怕也是。

代码:

  • 644K 0MS
//644K		0MS


#include <iostream>
#include <cstring>

using namespace std;

char mp[9][9];
char chess[9][9];

void init(){
	memset(mp,0,sizeof(mp));
	//对每个格子,行与列的奇偶性相同则为 ':' 
	//进一步,col + row 为偶则为 ':' 
	for(int i=1;i<=8;i++)
		for(int j=1;j<=8;j++)
			if((i + j)%2)
				mp[i][j] = '.';
			else
				mp[i][j] = ':';
	memcpy(chess,mp,sizeof(mp));
	return ;
}

void inputwhite(){
	char temp;
	for(int i=1;i<=6;i++)
		cin>>temp;
	while(true){	
		char fir,sec;
		int row , col;
		cin>>fir;
		if(fir>='A' && fir<='Z'){
			cin>>sec>>row;
			col = sec - 'a' + 1; 
			chess[row][col] = fir;
		}
		else{
			cin>>row;
			col = fir - 'a' + 1;
			chess[row][col] = 'P';
		}
		cin>>temp;
		if(temp != ',')
			break;
	}
	return ;
}

void inputblack(){
	char temp;
	for(int i=1;i<=5;i++)
		cin>>temp;
	while(true){	
		char fir,sec;
		int row , col;
		cin>>fir;
		if(fir>='A' && fir<='Z'){
			cin>>sec>>row;
			col = sec - 'a' + 1; 
			chess[row][col] = fir + 'a' - 'A';
		}
		else{
			cin>>row;
			col = fir - 'a' + 1;
			chess[row][col] = 'p';
		}
		if(cin>>temp)
			;
		else
			break;
	}
	return ;
}

void output(){
	for(int i=1;i<=17;i++){
		if(i%2)
			cout<<"+---+---+---+---+---+---+---+---+"<<endl;
		else{
			for(int j=1;j<=8;j++){
				cout<<'|'<<mp[9-i/2][j]<<chess[9-i/2][j]<<mp[9-i/2][j];
			}
			cout<<'|'<<endl;
		}
	}
	return ;
}

int main(){
	init();
	inputwhite();
	inputblack();
	output();
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值