Blue Jeans

http://poj.org/problem?id=3080

 1 #include<cstdio>
 2 #include<cstring>
 3 #include<algorithm>
 4 using namespace std;
 5 char s[100][100],s1[100],s2[100];
 6 int main()
 7 {
 8     int t,m,j,h;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         scanf("%d",&m);
13         s2[0]='\0';
14         bool flag=false;
15         for(int i=0; i<m; i++)
16         {
17             scanf("%s",s[i]);
18         }
19         for(j=0; j<60; j++)
20         {
21             int len=2;
22             while(j+len<60)
23             {
24                 int c=0;
25                 for(int i=j; i<=j+len; i++)
26                 {
27                     s1[c++]=s[0][i];
28                 }
29                 s1[c]='\0';
30                 for(h=1; h<m; h++)
31                 {
32                     if(strstr(s[h],s1)==NULL)
33                         break;
34                 }
35                 if(h==m)
36                 {
37                     if(strlen(s2)==strlen(s1))
38                     {
39                         if(strcmp(s2,s1)>0)
40                         {
41                             flag=true;
42                             strcpy(s2,s1);
43                         }
44                     }
45                     else if(strlen(s1)>strlen(s2))
46                     {
47                         flag=true;
48                         strcpy(s2,s1);
49                     }
50                 }
51                 len++;
52             }
53         }
54         if(flag) printf("%s\n",s2);
55         else printf("no significant commonalities\n");
56     }
57     return 0;
58 }
View Code

 

转载于:https://www.cnblogs.com/fanminghui/p/3268511.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值