Substrings substring-----Search

Source: Internet
Author: User

Description

You is given a number of case-sensitive strings of alphabetic characters, find the largest string x, such that either X, Or its inverse can is found as a substring of any of the given strings.

Input

The first line of the input file contains a single integer t (1 <= t <=), the number of test cases, followed by t He input data for each test case. The first line of all test case contains a single integer n (1 <= n <=), the number of given strings, followed by n lines, each representing one string of minimum length 1 and maximum length 100. There is no extra white space before and after a string.

Output

There should is one line per test case containing the length of the largest string found.

Sample Input

2 3abcdbcdffbrcd2roseorchid

Sample Output

22
#include<stdio.h>#include<string.h>#include<stdlib.h>#define MAXN105Char Lina[MAXN];Char A[MAXN][maxn];int x;voidLinstr(){int I;int Len=10000, Lens; Lina[0]=‘/‘;scanf("%d",&x);For(I=0; I<x; I++){scanf('%s '+ F[I]);int lens=Strlen(A[I]);If(len>lens){strcpy(Lina+ F[I]); Len= Lens;}}}IntFin(Char Str[],Char RTS[]){int I;For(I=0; I<x; I++){If(Strstr(A[I], str)==0&&Strstr(A[I], RTS)==0)Return0;}Return1;}IntFuck(){int ILenJ; Len=Strlen(Lina);For(I= Len; I>0; I--){For(j=0; J+i<=len; J++){Char Str[MAXN]={0}Rts[MAXN];strncpy(str, Lina+j, I);strcpy(RTSStr);Strrev(RTS);If(Fin(strRts)==1)return I;}}Return0;}IntMain(){int nNumscanf ( "%d" &n); while  (N--) { linstr () num = fuck (); printf ( "%d \n ");  return 0;< Span class= "Sh-cbracket" >             

Substrings substring-----Search

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.