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

暴力过的(0ms),代码贴一下!

Posted by N0_1 at 2010-07-19 17:29:52 on Problem 3080
# include<stdio.h>
# include<string.h>
int main()
{
	int i,j,n,m,k,h,num,ans,len;
	char str[20][65],st[65],s[65];
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&m);
		getchar();
		for(j=0;j<m;j++)
			gets(str[j]);
		len=strlen(str[0]);
		ans=0;
		for(j=0;j<len;j++)
		{
			for(k=j;k<len;k++)
			{
				num=0;
				for(h=j;h<=k;h++)
					st[num++]=str[0][h];
				st[num]=0;
				for(h=1;h<m;h++)
					if(strstr(str[h],st)==0) break;
					if(h==m&&ans<num)
					{
						ans=num;
						strcpy(s,st);
					}
					else if(h==m&&ans==num)
					{
						if(strcmp(s,st)>0) strcpy(s,st);
					}
			}
		}
		if(ans<3) printf("no significant commonalities\n");
		else puts(s);
	}
	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