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

那位大牛帮我看看我的什么地方错了,为什么总是wa

Posted by N0_1 at 2010-07-14 17:22:42 on Problem 3302
# include<stdio.h>
# include<string.h>
int main()
{
	int i,j,n,h,k,flag,word,la,lb;
	char str1[105],str2[105],str3[105];
	scanf("%d",&n);
	while(n--)
	{
		scanf("%s%s",str1,str2);
		la=strlen(str1);
		lb=strlen(str2);
		if(la<lb) {printf("NO\n");continue;}
		if(la==1&&str1[0]==str2[0]) {printf("YES\n");continue;} 
		for(i=0;i<=la-lb;i++)
		{
			word=0;
			if(str1[i]==str2[0])
			{
				k=i;
				for(j=1;j<=lb-1;j++)
				{
					flag=0;
					for(h=k+1;h<la;h++)
						if(str2[j]==str1[h]) {flag=1;k=h;break;}
						if(flag==0) break;
				}
				if(flag==1) word=1;
			}
			if(word==1) break;
		}
		if(word==1) {printf("YES\n");continue;}
		k=0;
		for(j=lb-1;j>=0;j--)
			str3[k++]=str2[j];
		str3[k++]=0;
		strcpy(str2,str3);
		for(i=0;i<=la-lb;i++)
		{
			word=0;
			if(str1[i]==str2[0])
			{
				k=i;
				for(j=1;j<=lb-1;j++)
				{
					flag=0;
					for(h=k+1;h<la;h++)
						if(str2[j]==str1[h]) {flag=1;k=h;break;}
						if(flag==0) break;
				}
				if(flag==1) word=1;
			}
			if(word==1) break;
		}
		if(word==1) printf("YES\n");
		else printf("NO\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