HDU 1238 ( Substrings )

Problem : 1238 ( Substrings )     Judge Status : Accepted
RunId : 5677664    Language : C++    Author : ssun
Code Render Status : Rendered By HDOJ C++ Code Render Version 0.01 Beta

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
    int t,n;
    string ss[110];
    scanf("%d",&t);
    while(t--)
    {
        int i,j,k,max=0;
        scanf("%d",&n);
        for(i=0; i<n; i++)
        {
            cin>>ss[i];
        }
        for(i=0; i<ss[0].size(); i++)
        {
            string temp;
            for(j=1; j<=ss[0].size()-i; j++)
            {
                temp.assign(ss[0],i,j);
        //        cout<<temp<<endl;
                for(k=1; k<n; k++)
                {
                    if(ss[k].find(temp,0)==-1) break;
                }
                if(k==n && j>max) max = j;
                for(k=1; k<n; k++)
                {
                    string s = ss[k];
                    reverse(s.begin(),s.end());
                //    cout<<s<<endl;
                    if(s.find(temp,0)==-1) break;
                }
                if(k==n && j>max) max = j;
            }
        }
        printf("%d\n",max);
    }
    return 0;
}

你可能感兴趣的:(HDU 1238 ( Substrings ))