poj 3080 Blue Jeans(水题 暴搜)

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

水题,暴搜

 1 #include <iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<stack>
 6 #include<queue>
 7 #include<iomanip>
 8 #include<cmath>
 9 #include<map>
10 #include<vector>
11 #include<algorithm>
12 using namespace std;
13 int main()
14 {
15     int t,i,j,k,n,f,cnt;
16     char s[100][100],a[100],b[100];
17     cin>>t;
18     while(t--)
19     {
20         f=0;  memset(b,0,sizeof(b)); b[1]='';
21         cin>>n;
22         getchar();
23         for(i=0; i<n; i++)
24             cin>>s[i];
25         for(i=0; i<60; i++)
26         {
27             for(j=i+2; j<60; j++)
28             {
29                 cnt=0;  memset(a,0,sizeof(a));
30                 for(k=i; k<=j; k++)
31                 a[cnt++]=s[0][k];
32                 a[k]='';
33                 for(k=1; k<n; k++)
34                 {
35                     if(strstr(s[k],a)==NULL)
36                     break;
37                     if(k==n-1)
38                     {
39                         f=1;
40                         if(strlen(a)>strlen(b))
41                         strcpy(b,a);
42                         if(strlen(a)==strlen(b)&&strcmp(a,b)<0)
43                         strcpy(b,a);
44                     }
45                 }
46             }
47         }
48 
49         if(f==0) cout<<"no significant commonalities"<<endl;
50         else cout<<b<<endl;
51     }
52     return 0;
53 }
原文地址:https://www.cnblogs.com/bfshm/p/3267624.html