我希望你是我独家记忆

一段永远封存的记忆,随风而去
posts - 263, comments - 31, trackbacks - 0, articles - 3
   :: 首页 :: 新随笔 ::  :: 聚合  :: 管理

P1226

Posted on 2008-09-06 19:11 Hero 阅读(98) 评论(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     forint i=1; i<=inn; i++ )
20     {
21         scanf( "%s", data[i] ) ;
22     }
23 }
24 
25 bool test()
26 {
27     forint 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     forint clen=len; clen>=0; clen-- )
40     {
41         forint sn=0; sn+clen<=len; sn++ )        
42         {
43             cstra = cstrb = 0 ;
44             forint i=sn; i<sn+clen; i++ ) stra[cstra++= data[1][i] ;
45             forint 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         forint ct=1; ct<=innum; ct++ )
66         {
67             input() ;
68 
69             process() ;
70 
71             //output() ;
72         }
73     }
74 
75     return 0 ;
76 }

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理