hdu 1014

#include <iostream>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <vector>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <cctype>
#include <iomanip>
using namespace std;

typedef long long ll;
typedef long double ld;

const int N = 110;
const int INF = 0xfffffff;
const double EPS = 1e-8;
const ll MOD = 1e9 + 7;
const ld PI = acos (-1.0);

#define INFL 0x7fffffffffffffffLL
#define met(a, b) memset(a, b, sizeof(a))
#define put(a) cout << setiosflags(ios::fixed) << setprecision(a)

int dp[N];

int main ()
{
    int T, n;
    cin >> T;
    while (T--)
    {
        cin >> n;
        char str[N][N], minstr[N], s[N], r[N];
        int len = 110, i, j, k;

        for (i=0; i<n; i++)
        {
            cin >> str[i];
            if (strlen (str[i]) < len)
            {
                strcpy (minstr, str[i]);
                len = strlen (str[i]);
            }
        }
        int flag;

        for  (i=len; i>=1; i--)
        {
            for (j=0; j<len; j++)
            {
                strncpy (s, minstr+j, i);
                strncpy (r, minstr+j, i);
                s[i] = '\0';
                r[i] = '\0';
                strrev (r);

                flag = 0;
                for (k=0; k<n; k++)
                {
                    if (strstr (str[k], s) == NULL && strstr (str[k], r) == NULL)
                    {
                        flag = 1;
                        break;
                    }
                }
                if (!flag)
                {
                    cout << strlen (s) << endl;
                    break;
                }
            }
            if (!flag)
                break;
        }
        if (flag)
            cout << 0 << endl;
    }
    return 0;
}

/*
5
3
abcba
ababc
cbaba
3
a
b
c

*/

你可能感兴趣的:(hdu 1014)