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

【AC】暴力枚举子串

Posted by jingzhibao at 2015-02-14 11:09:05 on Problem 3080
#include<cstdio>
#include<cstring>
const int maxm = 10 + 5;
const int maxs = 60 + 5;

int main()
{
	int loop;
	scanf("%d", &loop);
	while (loop--)
	{
		int m;
		char p[maxm][maxs];
		scanf("%d", &m);
		for (int i = 0; i < m; i++)
		{
			scanf("%s", p[i]);
		}
		int len;
		char ans[maxs];
		len = 0;
		for (int i = 0; i < strlen(p[0]); i++)
		{
			for (int j = i + 2; j < strlen(p[0]); j++)
			{
				char s[maxs];
				strncpy(s, p[0] + i, j - i + 1);
				s[j - i + 1] = '\0';
				bool ok = true;
				for (int k = 1; ok && k < m; k++)
				{
					if (strstr(p[k], s) == NULL)
					{
						ok = false;
					}
				}
				if (ok && (j - i + 1 > len || (j - i + 1 == len && strcmp(ans, s) > 0)))
				{
					len = j - i + 1;
					strcpy(ans, s);
				}
			}
		}
		if (len < 3)
		{
			printf("no significant commonalities\n");
		}
		else
		{
			printf("%s\n", ans);
		}
	}
	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