微软笔试题(苏州)

题目是  小明迷路了,求出他的方位,具体的题目没了,所以没有弄过来,希望大家海涵或者提供一下


#include <iostream>
#include <utility>
#include <fstream>
using namespace std;

int N;
int M;
char ** allmap;
char ** side;
int const side_length = 3;


const pair<int,int> error = make_pair(-1,-1);




bool northcheckplace(int x,int y);
void getdata();
void findplace();
bool eastcheckplace(int x,int y);
bool sourthcheckplace(int x,int y);
bool westhcheckplace(int x,int y);
void readdata();



int main()
{
getdata();
//readdata();
	findplace();
	system("pause");
	return 0;
}

void getdata()
{
	cin>>N;
	cin>>M;
	allmap = new char*[N];
	for(int i=0;i<N;i++)
	{
		allmap[i] = new char[M];
		for(int j=0;j<M;j++)
		{
			cin>>allmap[i][j];
		}
	}

	side = new char*[side_length];
	for(int i=0;i<side_length;i++)
	{
		side[i] = new char[side_length];
		for(int j=0;j<side_length;j++)
		{
			cin>>side[i][j];
		}
	}
}

void findplace()
{
	pair<int,int> result;
	result  = error;
	for(int i=0;i <= N-side_length;i++)
		for(int j=0;j <= M-side_length;j++)
		{
			if( northcheckplace(i,j) == true )
				cout<<i+2<<" "<<j+2<<endl;
			else if( eastcheckplace(i,j) == true )
			{
				cout<<i+2<<" "<<j+2<<endl;
			}
			else if( sourthcheckplace(i,j) == true )
			{
				cout<<i+2<<" "<<j+2<<endl;
			}
			else if( westhcheckplace(i,j) == true )
			{
				cout<<i+2<<" "<<j+2<<endl;
			}
			
		}
}


bool northcheckplace(int x,int y)
{

	for(int i=0;i<side_length;i++)
		for(int j=0;j<side_length;j++)
		{
			if(allmap[x+i][y+j] != side[i][j])
				return false;
		}

		return true;
}


bool eastcheckplace(int x,int y)
{

	for(int i=0;i<side_length;i++)
		for(int j=0;j<side_length;j++)
		{
			if(allmap[x+i][y+j] != side[side_length-j-1][i])
				return false;
		}

	return true;
}

bool sourthcheckplace(int x,int y)
{

	for(int i=0;i <side_length ;i++)
		for(int j=0;j <side_length;j++)
		{
			if(allmap[x+i][y+j] != side[side_length-1-i][side_length-1-j])
				return false;
		}

		return true;
}


bool westhcheckplace(int x,int y)
{

	for(int i=0;i<side_length;i++)
		for(int j=0;j<side_length;j++)
		{
			if(allmap[x+i][y+j] != side[j][side_length-1-i])
				return false;
		}

		return true;
}




void readdata()
{
	ifstream reader;
	reader.open("data.txt");
	reader>>N;
	reader>>M;
	allmap = new char*[N];
	for(int i=0;i<N;i++)
	{
		allmap[i] = new char[M];
		for(int j=0;j<M;j++)
		{
			reader>>allmap[i][j];
		}
	}

	side = new char*[side_length];
	for(int i=0;i<side_length;i++)
	{
		side[i] = new char[side_length];
		for(int j=0;j<side_length;j++)
		{
			reader>>side[i][j];
		}
	}
	reader.close();
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值