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 1340502116 at 2016-02-18 21:54:28 on Problem 1226
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[105][105];
int n;
int solve()
{
	char sub[105];
	char rsub[105];
	int len=strlen(s[0]);
	int cnt=0;
	for(int l=len;l>0;l--)
	{
		for(int x=0;x+l<=len;x++)
		{
			memset(sub,0,sizeof(sub));
			memset(rsub,0,sizeof(rsub));
			strncpy(sub,s[0]+x,l);
			strcpy(rsub,sub);
			reverse(rsub,rsub+strlen(rsub));
			cnt=0;
			for(int i=1;i<n;i++)
			{
				if(strstr(s[i],sub)!=NULL||strstr(s[i],rsub)!=NULL)
				{
					cnt++;
				}
				else	break;
			}
			if(cnt==n-1)	return strlen(sub);
		}
	}	
	return 0;
}
int main()
{
	int cas;
	scanf("%d",&cas);
	while(cas--)
	{
		scanf("%d",&n);
		memset(s,0,sizeof(s));
		for(int i=0;i<n;i++)
		{
			scanf("%s",s[i]);
		}
		printf("%d\n",solve());
	}
    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