// 难道这题是让我们复习string用法...
Gssn
1 Source Code
2
3 Problem: 3080 User: eth1
4 Memory: 744K Time: 63MS
5 Language: G ++ Result: Accepted
6
7 Source Code
8 #include < iostream >
9 #include < string >
10 #include < cmath >
11 #include < algorithm >
12 #include < cstdio >
13 #include < cstring >
14 #include < map >
15
16 using namespace std;
17 string f[ 15 ];
18 int n;
19 void solve()
20 {
21 string tem,ans[ 61 ];
22 int flag = 0 ,i,m;
23 for (i = 60 ;i >= 1 ;i -- )
24 {
25 m = 0 ;
26 for ( int j = 0 ;j + i <= 60 ;j ++ )
27 {
28 tem = f[ 0 ].substr(j,i);
29 int k;
30 for (k = 1 ;k < n;k ++ )
31 {
32 if (f[k].find(tem) ==- 1 )
33 {
34 break ;
35 }
36 }
37 if (k == n) {flag = 1 ;ans[m ++ ] = tem;}
38 }
39 if (flag) break ;
40 }
41 if (i < 3 ) {cout << " no significant commonalities " << endl; return ;}
42 sort(ans,ans + m);
43 cout << ans[ 0 ] << endl;
44 }
45 int main()
46 {
47 int t;
48 cin >> t;
49 while (t -- )
50 {
51 cin >> n;
52 for ( int i = 0 ;i < n;i ++ )
53 cin >> f[i];
54 solve();
55 }
56 return 0 ;
57 }
2
3 Problem: 3080 User: eth1
4 Memory: 744K Time: 63MS
5 Language: G ++ Result: Accepted
6
7 Source Code
8 #include < iostream >
9 #include < string >
10 #include < cmath >
11 #include < algorithm >
12 #include < cstdio >
13 #include < cstring >
14 #include < map >
15
16 using namespace std;
17 string f[ 15 ];
18 int n;
19 void solve()
20 {
21 string tem,ans[ 61 ];
22 int flag = 0 ,i,m;
23 for (i = 60 ;i >= 1 ;i -- )
24 {
25 m = 0 ;
26 for ( int j = 0 ;j + i <= 60 ;j ++ )
27 {
28 tem = f[ 0 ].substr(j,i);
29 int k;
30 for (k = 1 ;k < n;k ++ )
31 {
32 if (f[k].find(tem) ==- 1 )
33 {
34 break ;
35 }
36 }
37 if (k == n) {flag = 1 ;ans[m ++ ] = tem;}
38 }
39 if (flag) break ;
40 }
41 if (i < 3 ) {cout << " no significant commonalities " << endl; return ;}
42 sort(ans,ans + m);
43 cout << ans[ 0 ] << endl;
44 }
45 int main()
46 {
47 int t;
48 cin >> t;
49 while (t -- )
50 {
51 cin >> n;
52 for ( int i = 0 ;i < n;i ++ )
53 cin >> f[i];
54 solve();
55 }
56 return 0 ;
57 }