标签:
Description
Input
Output
Sample Input
Sample Output
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 120
char str[maxn][maxn];
char source[maxn];
int n;
void Input()
{
int i, len = 1000;
scanf("%d", &n);
source[0] = ‘\0‘;
for(i = 0; i < n; i++)
{
scanf("%s", str[i]);
int lens = strlen(str[i]);
if(len > lens)
{
strcpy(source, str[i]);
len = lens;
}
}
}
int Find(char substrs[], char revsubstr[])
{
for(int i = 0; i < n; i++)
{
if(strstr(str[i], substrs) == 0 && strstr(str[i], revsubstr) == 0)
return 0;
}
return 1;
}
int substring()
{
int i, j, len = strlen(source);
for(i = len; i > 0; i--)
for(j = 0; j + i <= len; j++)
{
char substrs[maxn] = {0}, revsubstr[maxn];
strncpy(substrs, source+j, i);
strcpy(revsubstr, substrs);
strrev(revsubstr);
if(Find(substrs, revsubstr))
return i;
}
return 0;
}
int main()
{
int t;
scanf("%d", &t);
while(t--)
{
Input();
printf("%d\n", substring());
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/Tinamei/p/4234749.html