1.鏈接地址:http://poj.org/problem?id=1226
2.題目:
Substrings Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 10252 Accepted: 3519Description
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 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 orchidSample Output
2 2Source
Tehran 2002 Preliminary
3.代碼:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <.h>
NUM = strs[NUM][NUM +
cin>>
(t-- cin>> cin.
( i = ; i < n; i++ scanf(
( i = ; i < n; i++
length = strlen(strs[ substr[NUM + ],substr2[NUM + res = ( i = ; i <= length; i++ ( j = ; (j+i-) < length; j++ strncpy(substr,&strs[ substr[i] =
( k = ; k < (i+)/; k++ tmp = substr2[k] = substr2[i-- substr2[i--k] =
(k = ; k < n; k++ (!strstr(strs[k],substr) && !strstr(strs[k],substr2)) (k >= res =
cout<<res<< }
4.思路:
1.遍歷所有的可能串,在查找是否符合。效率不是一般的差,不過對付這個簡單還是可以的
2.看見書裡推薦用strrev,但是無論是G++,C++都沒有這個函數