标签:
题目是 小明迷路了,求出他的方位,具体的题目没了,所以没有弄过来,希望大家海涵或者提供一下
#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