| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
【AC】暴力枚举子串#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator