Posted on 2008-09-06 19:11
Hero 阅读(103)
评论(0) 编辑 收藏 引用 所属分类:
代码如诗--ACM
1 //1226 Accepted 216K 16MS C++ 1202B PKU
2
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 const int size = 200 ;
8 char data[size][120] ;
9
10 char stra[120] ;
11 char strb[120] ;
12
13 int innum ;
14 int inn ;
15
16 void input()
17 {
18 scanf( "%d", &inn ) ;
19 for( int i=1; i<=inn; i++ )
20 {
21 scanf( "%s", data[i] ) ;
22 }
23 }
24
25 bool test()
26 {
27 for( int i=2; i<=inn; i++ )
28 {
29 if( NULL==strstr(data[i], stra)&&NULL==strstr(data[i], strb) ) return false ;
30 }
31
32 return true ;
33 }
34
35 void process()
36 {
37 int len = strlen( data[1] ) ; int cstra, cstrb ; bool hasfind = false ;
38
39 for( int clen=len; clen>=0; clen-- )
40 {
41 for( int sn=0; sn+clen<=len; sn++ )
42 {
43 cstra = cstrb = 0 ;
44 for( int i=sn; i<sn+clen; i++ ) stra[cstra++] = data[1][i] ;
45 for( int i=clen-1; i>=0; i-- ) strb[cstrb++] = stra[i] ;
46 //printf( "%s==%s\n", stra, strb ) ;
47
48 stra[clen] = strb[clen] = '\0' ;
49
50 if( test() )
51 {
52 hasfind = true ; printf( "%d\n", clen ) ; break ;
53 }
54 }
55 if( hasfind ) break ;
56 }
57
58 if( !hasfind ) printf( "0\n" ) ;
59 }
60
61 int main()
62 {
63 while( scanf( "%d", &innum ) != EOF )
64 {
65 for( int ct=1; ct<=innum; ct++ )
66 {
67 input() ;
68
69 process() ;
70
71 //output() ;
72 }
73 }
74
75 return 0 ;
76 }