Substrings substring ----- search, substrings -----
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 shoshould be one line per test case containing the length of the largest string found.
Sample Input
2 3ABCDBCDFFBRCD2roseorchid
Sample Output
22. In the given string, find the oldest string that appears in all strings. Train of Thought: first find the shortest string and then use its sub-string to search for it, in order to optimize the operation, because to find the longest substring, first start with the sub-String Of The len Length; the length of the sub-string decreases in turn, make sure that the request is set as the eldest son string. The combination of multiple functions helps to refine the problem.
# Include <stdio. h> # include <string. h> # include <stdlib. h> # define maxn 105 char lina [maxn]; char a [maxn] [maxn]; int x; void linstr () // find the string with the smallest length {int I; int len = 10000, lens; lina [0] = '\ 0'; scanf ("% d", & x); for (I = 0; I <x; I ++) {scanf ("% s", a [I]); int lens = strlen (a [I]); if (len> lens) {strcpy (lina, a [I]); len = lens ;}} int fin (char str [], char rts []) // determine whether the extracted substring contains {int I; for (I = 0; I <x; I ++) {if (strstr (a [I], str) = 0 & strstr (a [I], rts) = 0) return 0;} return 1 ;} int fuck () {int I, len, j; 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 ); // set the I character cpy starting from j in lina to strcpy (rts, str); strrev (rts ); // The inverted function is used by many oj instances that do not support the inverted function. You need to write another function to complete the inverted function. if (fin (str, rts) = 1) // determine whether str and its inverted function meet the return I;} return 0;} int main () {int n, num; scanf ("% d ", & n); while (n --) {linstr (); num = fuck (); printf ("% d \ n", num);} return 0 ;}