百练4092:牛仔裤

传送门:http://bailian.openjudge.cn/practice/4092

【题解】

这啥玩意儿啊写个暴力就没了

怎么一直wa啊。。。

注意要把ans清空啊。。。wori

# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm>
// # include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
const int M = 5e5 + 10;
const int mod = 1e9+7;

# define RG register
# define ST static

int n;
char s[11][66];

char ans[66], t[66];

inline bool ok(char *t, char *s, int l) {
    for (int i=0; i<l; ++i)
        if(t[i] < s[i]) return 1;
        else if(t[i] > s[i]) return 0;
    return 0;
}

int main() {
    int T; cin >> T;
    while(T--) {
        bool have = 0;
        cin >> n;
        for (int i=1; i<=n; ++i) scanf("%s", s[i]+1);
        for (int len=60; len>=3; --len) {
            bool oo = 0;
            for (int j=1; j<=61-len; ++j) {
                bool gg2 = 0;
                for (int nx=2; nx<=n; ++nx) {
                    bool suc = 0;
                    for (int nb=1; nb<=61-len; ++nb) {
                        bool gg = 0;
                        for (int o=0; o<len; ++o)
                            if(s[1][j+o] != s[nx][nb+o]) {
                                gg = 1;
                                break;
                            }
                        if(!gg) {
                            suc = 1;
                            break;
                        }
                    }
                    if(!suc) {
                        gg2 = 1;
                        break;
                    }
                }
                if(gg2) continue;
                for (int k=0; k<len; ++k) t[k] = s[1][j+k]; t[len] = 0;
                if(!oo || ok(t, ans, len)) {
                    for (int k=0; k<len; ++k) ans[k] = t[k];
                    ans[len] = 0;
                    oo = 1;
                }
            }
            if(!oo) continue;
            have = 1;
            printf("%s\n", ans);
            break;
        }
        if(!have) puts("no significant commonalities");
    }
    return 0;
}
View Code

 

posted @ 2017-05-17 09:45  Galaxies  阅读(204)  评论(0编辑  收藏  举报