Substrings
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6238 Accepted Submission(s): 2767
Problem Description
You are given a number of case-sensitive strings of alphabetic characters, find the largest string X, such that either X, or its inverse can be 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 <= 10), the number of test cases, followed by the input data for each test case. The first line of each test case contains a single integer n (1 <= n <= 100), 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 be one line per test case containing the length of the largest string found.
Sample Input
2
3
ABCD
BCDFF
BRCD
2
rose
orchid
Sample Output
2
2
Author
Asia 2002, Tehran (Iran), Preliminary
Recommend
Eddy
1 //寻找最长字串并输出其长度 2 // 思路: 3 // 1、先寻找其中最短字符串str,求子字符串就要先找最短的字符串 4 // 2、根据str搜索满足条件的子字符串 5 // 3、对str的各子字符串从长到短一次判断是否满足条件,直到找到一个符合条件的子字符串为止 6 //strlen:计算字符串长度 7 //strstr:在字符串中寻找子字符串,它的用法用的少,但是碰到了,就要熟练。 8 //strncpy:复制字符串中的字串,它的用法要掌握。 9 //strcpy:复制字符串 10 //怎样找最短字符串,也是值得学习的。。 11 //搜索满足条件的最长子串. 12 #include<stdio.h> 13 #include<string.h> 14 char a[101][101]; 15 int n; 16 void cmp(char *str)//字符串反序 17 { 18 int l,i,g=0; 19 char b[101]; 20 l=strlen(str); 21 for(i=0;i<l;i++) 22 b[g++]=str[l-i-1]; 23 b[g]='