码迷,mamicode.com
首页 > 其他好文 > 详细

微软笔试题(苏州)

时间:2015-01-07 23:37:41      阅读:325      评论:0      收藏:0      [点我收藏+]

标签:

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


#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();
}


微软笔试题(苏州)

标签:

原文地址:http://blog.csdn.net/cqs_experiment/article/details/42503893

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!