#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
int t, n, i;
cin >> t;
while(t--)
{
string s[101];
cin >> n;
int len = 1000, j = 0, max, f = 0;
for(i = 0; i < n; i++)
{
cin >> s[i];
if(s[i].size() < len)
{
len = s[i].size();
j = i;
}
}
max = len;
string str;
str = s[0];
s[0] = s[j];
s[j] = str;
while(len)
{
for(i = 0; i + len <= max; i++)
{
str = s[0].substr(i, len);
for(j = 1; j < n; j++)
if(s[j].find(str) == -1)
break;
if(j == n)
{
f = 1;
break;
}
char t;
for(j = 0; j < len / 2; j++)
{
t = str[j];
str[j] = str[len - 1 - j];
str[len - 1 -j] = t;
}
for(j = 1; j <=n; j++)
if(s[j].find(str) == -1)
break;
if(j == n)
{
f = 1;
break;
}
}
if(f)
break;
len--;
}
cout << len << endl;
}
return 0;
}
HDU 1238 Substring
最新推荐文章于 2021-07-21 16:03:18 发布