百练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

 

转载于:https://www.cnblogs.com/galaxies/p/bailian4092.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值