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 fjnu_jxd_010 at 2005-08-09 01:44:53 on Problem 1501
#include<iostream>
using namespace std;
char a[200][200],k[200];
int l;
int as(int i,int j,int &a1,int &b)
{
	int flag=0,t,j1;
 for(j1=j,t=0;t<strlen(k);j1++,t++)
		if(a[i][j1]!=k[t])
			{flag=1;break;}
		if(flag==0)
		{ 
			a1=i,b=j+strlen(k)-1; return 1;
		}
		else if(flag==1&&j>=strlen(k))
		{ 
			for(j1=j,t=0;t<strlen(k);t++,j1--)
				  if(a[i][j1]!=k[t])
				  {flag=0;break;}
			if(flag==1)
			{ a1=i,b=j-strlen(k)+1; return 1;}
		
			else return 0;
		}
		else return 0;
}
int ts(int i,int j,int &a1,int &b)
{
	int flag=0,t,i1;
 for(i1=i,t=0;t<strlen(k);i1++,t++)
		if(a[i1][j]!=k[t])
			{flag=1;break;}
		if(flag==0)
   { b=j,a1=i+strlen(k)-1; return 1;}
	//	else if(flag==1&&j>=strlen(k))
             // for(i1=i,t=0;t<strlen(k);t++,i1++)
			//	  if(a[i1][j]!=k[t])
			//	  {flag=0;break;}
		//	if(flag==1)
  // { a=i-strlen(k)+1,b=j; return 1;}
			else return 0;
}

int ds(int &i1,int &j1,int &i0,int &j0)
{
	//char d1[200],d2[200],d3[200],d4[200];
	//for(i=0;i<strlen(k);i++)
	int j,t,i;
		for(j=1;j<=l;j++)
		if(k[0]==a[j][j]&&l-j+1>=strlen(k))
		{
			int flag=0;
			for(i=j,t=0;t<strlen(k);i++,t++)
			   if(k[t]!=a[i][i])
			   {flag=1;break;}

		if(flag==0)
		{i0=i-1;j0=i-1;i1=j;j1=j;return 1;}
		}
		return 0;
}
int ss(int &i1,int &j1,int &i0,int &j0)
{
	int j,i,t;
	for(j=l;j>=1;j--)
		if(k[0]==a[j][j]&&j>=strlen(k))
		{
			int flag=0;
			for(i=j,t=0;t<strlen(k);i--,t++)
			   if(k[t]!=a[i][i])
			   {flag=1;break;}

		if(flag==0)
		{i0=i+1;j0=i+1;i1=j;j1=j;return 1;}
		}
		return 0;
}
int ks(int &i1,int &j1,int &i0,int &j0)
{
	int j,i,t;
	for(j=l;j>=1;j--)
		if(k[0]==a[j][l-j+1]&&j>=strlen(k))
		{
			int flag=0;
			for(i=j,t=0;t<strlen(k);i--,t++)
			   if(k[t]!=a[i][l-i+1])
			   {flag=1;break;}

		  if(flag==0)
		  {i0=i+1;j0=l-(i+1)+1;i1=j;j1=l-j+1;return 1;}
		}
		return 0;
}
int es(int &i1,int &j1,int &i0,int &j0)
{
	int j,i,t;
	for(j=l;j>=1;j--)
		if(k[0]==a[l-j+1][j]&&j>=strlen(k))
		{
			int flag=0;
			for(i=j,t=0;t<strlen(k);i--,t++)
			   if(k[t]!=a[l-i+1][i])
			   {flag=1;break;}

		  if(flag==0)
		  {i0=l-(i+1)+1;j0=i+1;i1=l-j+1;j1=j;return 1;}
		}
		return 0;
}

int main()
{
	int i,j,i0,j0;
	
	
	cin>>l;
for(i=1;i<=l;i++)
for(j=1;j<=l;j++)
{cin>>a[i][j];}//cout<<a[i][j]<<endl;

char y[200];y[0]='0',y[1]='\0';//cout<<y<<endl;
   while(cin>>k&&(strcmp(k,y))==1)
   {
//cout<<k[0]<<endl;
	   int set=0;
	   for(i=1;i<=l;i++)
	   {
		   for(j=1;j<=l;j++)
	             if(k[0]==a[i][j])
				 {
					if(as(i,j,i0,j0))
					{printf("%d,%d %d,%d\n",i,j,i0,j0);set=1;break;}
                   else 	if( ts(i,j,i0,j0))
				   {printf("%d,%d %d,%d\n",i,j,i0,j0);set=1;break;}
	               
				 }
				 
				 if(set==1)
					 break;
	   }
	   if(set==0)
	   { if(ds(i,j,i0,j0)||ss(i,j,i0,j0)||es(i,j,i0,j0)||ks(i,j,i0,j0))//
				   {	printf("%d,%d %d,%d\n",i,j,i0,j0);}
	   else 
		   cout<<"Not found\n";
	   }
   }
   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