Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

谁有我的麻烦

Posted by baihui212 at 2010-03-21 17:51:36 on Problem 1501
#include <iostream>

using namespace std;


char a[101][101];

char word[101];

int result;

int n;

int search(char a[101][101], char word[101], int x, int y, int w, int flag){

	//cout<<strlen(a[1]);
		
	
	if(a[x][y] == word[w]){
	
//cout<<"a[x][y],word[w]::"<<x<<y<<w<<flag<<"::"<<a[x][y]<<"::"<<word[w]<<endl;
	

	int	w_len = strlen(word);
	if(w_len==w+1) {
		
		if(100==flag)	cout<<x+1<<","<<y+1<<" "<<x+1<<","<<y+1<<endl;
		else if(0==flag) cout<<x+1<<","<<y+2-w_len<<" "<<x+1<<","<<y+1<<endl;
		else if(1==flag) cout<<x+2-w_len<<","<<y+1<<" "<<x+1<<","<<y+1<<endl;
		else if(2==flag) cout<<x+2-w_len<<","<<y+2-w_len<<" "<<x+1<<","<<y+1<<endl;
		else if(3==flag) cout<<x+w_len<<","<<y+1<<" "<<x+1<<","<<y+1<<endl;
		else if(4==flag) cout<<x+w_len<<","<<y+2-w_len<<" "<<x+1<<","<<y+1<<endl;
		else if(5==flag) cout<<x+1<<","<<y+w_len<<" "<<x+1<<","<<y+1<<endl;
		else if(6==flag) cout<<x+w_len<<","<<y+w_len<<" "<<x+1<<","<<y+1<<endl;
		else if(7==flag) cout<<x+2-w_len<<","<<y+w_len<<" "<<x+1<<","<<y+1<<endl;
		result = 1;
		return 1;//OK
	};
	
	if(0==flag || 100==flag)
	//右边
	if((strlen(a[x])-y)>=(w_len-w)) search(a,word,x,y+1,w+1,0);

	if(1==flag ||  100==flag)
	//下边
	if((n-x)>=(w_len-w)) search(a,word,x+1,y,w+1,1);

	if(2==flag ||  100==flag)
	//右下
	if((strlen(a[x])-y)>=(w_len-w) && (n-x)>=(w_len-w)) search(a,word,x+1,y+1,w+1,2);

	//上边
	if(3==flag || 100==flag)
	if(x>=(w_len-1-w)) search(a,word,x-1,y,w+1,3);

	//右上
	if(4==flag || 100==flag)
	if((strlen(a[x])-y)>=(w_len-w) && x>=(w_len-1-w)) search(a,word,x-1,y+1,w+1,4);

	//左边
	if(5==flag || 100==flag)
	if(y>=(w_len-1-w)) search(a,word,x,y-1,w+1,5);

	//左上
	if(6==flag || 100==flag)
	if(x>=(w_len-1-w) && y>=(w_len-1-w)) search(a,word,x-1,y-1,w+1,6);

	//左下
	if(7==flag || 100==flag)
	if((n-x)>=(w_len-w) && y>=(w_len-1-w)) search(a,word,x+1,y-1,w+1,7);

	}
};


int main(){
	
	int i,j;
    
	cin>>n;
	for(i=0;i<n;i++)
		cin>>a[i];

//  	for(i=0;i<n;i++)
//  		cout<<strlen(a[i]);


	while(cin>>word) {
		result=0;
		if(word[0]=='0' && strlen(word)==1) break;

	 	for(i=0;i<n;i++)
				for( j=0;j<n;j++)
		search(a,word,i,j,0,100);
		//cout<<"result: "<<result<<endl;
		if(!result) cout<<"Not found"<<endl;
		
	}
	

	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator