POJ 1558 Board Silly G++

#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
//英语       抄博友程序      模拟 
string p;
char da[10][10];
int hang[10];
int lie[10];
vector<string> jg;
void find(int x,int y,int dx,int dy,int step)
{
	//cout<<x<<" "<<y<<" "<<dx<<" "<<dy<<" "<<step<<endl;
	for(int i=x+dx,j=y+dy,js=1;js!=step;i=i+dx,j=j+dy,js++)
	{
		if(i>=0 && i<8 && j>=0 && j<8)
		{
			if(da[i][j]!=p[0]&&da[i][j]!='.')
			{
				//cout<<"fh0"<<endl;
				return;
			}
		}else
		{
			//cout<<"fh1"<<endl;
			return;
		}
	}
	if((x+step*dx)>=0 && (x+step*dx)<8 &&(y+step*dy)>=0&& (y+step*dy)<8&&da[x+step*dx][y+step*dy]!=p[0])
	{
		//cout<<"hi"<<endl;
		string fh="";
		fh=fh+(char)(x+'A');
		fh=fh+(char)(y+'1');
		fh=fh+'-';
		fh=fh+(char)(x+step*dx+'A');
		fh=fh+(char)(y+step*dy+'1');
		//cout<<fh<<endl;
		jg.push_back(fh);		
	}
}
int main()
{
	while(1)
	{
		memset(hang,0,sizeof(hang));
		memset(lie,0,sizeof(lie));
		jg.clear();		
		for(int i=0;i<8;i++)
		{
			for(int j=0;j<8;j++)
			{
				cin>>da[i][j];
				if(cin.eof()==1)
				{
					return 0;
				}
				if(da[i][j]!='.')
				{
					hang[i]++;
					lie[j]++;					
				}
			} 
		}
		/*
		for(int i=0;i<8;i++)
		{
			for(int j=0;j<8;j++)
			{
				cout<<da[i][j];
			} 
			cout<<endl;
		}*/		
		cin>>p;
		//cout<<p<<endl;
		for(int i=0;i<8;i++)
		{
			for(int j=0;j<8;j++)
			{
				if(da[i][j]==p[0])
				{
					find(i,j,1,0,lie[j]);
					find(i,j,-1,0,lie[j]);
					find(i,j,0,1,hang[i]);
					find(i,j,0,-1,hang[i]);
					int js=1;
					for(int ti=i+1,tj=j+1;ti<8&&tj<8;ti++,tj++)
					{
						if(da[ti][tj]!='.')
						{
							js++;
						}
					}
					//cout<<js<<endl;
					for(int ti=i-1,tj=j-1;ti>=0&&tj>=0;ti--,tj--)
					{
						if(da[ti][tj]!='.')
						{
							js++;
						}
					}
					//cout<<js<<endl;
					find(i,j,1,1,js);
					find(i,j,-1,-1,js);
					js=1;
					for(int ti=i+1,tj=j-1;ti<8&&tj>=0;ti++,tj--)
					{
						if(da[ti][tj]!='.')
						{
							js++;
						}
					}
					for(int ti=i-1,tj=j+1;ti>=0&&tj<8;ti--,tj++)
					{
						if(da[ti][tj]!='.')
						{
							js++;
						}
					}
					find(i,j,1,-1,js);
					find(i,j,-1,1,js);
				}
			}
		}
		if(jg.size()==0)
		{
			cout<<"No moves are possible"<<endl<<endl;
		}else
		{
			sort(jg.begin(),jg.end());
			for(int i=0;i<jg.size();i++)
			{
				cout<<jg[i]<<endl;
			}
			cout<<endl;
		}				
	}
	return 0;
} 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值