标签:
#include <stdio.h>
#include <string.h>
#include <string>
#include <algorithm>
#include <iostream>
using namespace std;
int cmp(const string p,const string q)
{
return p.length()<q.length();
}
int main()
{
freopen("read.txt", "r", stdin);
string str[200];
int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
string tp;
for(int i=0; i<n; i++)
cin >> str[i];
sort(str, str+n, cmp);
int length = str[0].length();
int result = 0;
for(int i=0; i<length; i++)
{
bool sign = 1;
tp.clear();
for(int j=i+1; j<=length && sign; j++)
{
tp.assign(str[0], i, j-i);
for(int k =0; k<n; k++)
{
if(str[k].find(tp) == str[k].npos)
{
reverse(str[k].begin(), str[k].end() );
if(str[k].find(tp) == str[k].npos)
{sign = 0; break;}
}
}
if(sign)
{
if(result < j-i) result = j-i;
}
}
}
printf("%d\n", result);
}
return 0;
}
标签:
原文地址:http://www.cnblogs.com/sober-reflection/p/cfa2491ab85ce90994ab6d454df5189c.html