zoukankan      html  css  js  c++  java
  • POJ3080 Blue Jeans

    题目链接

    题目大意:

    给定n个字符串,找出最长相同且长度大于3的子串,如果存在多个,找出字典序最小的。

    分析:

    直接枚举(暴搜)。

    对于s[0]的每一个子串,判断是否在其它n-1个字符串中都存在。

    #include <iostream>
    #include <cstdio>
    #include <string>
    #include <map>
    
    using namespace std;
    
    #define N 60
    
    string s[30], str, str_max;
    
    int main(){
        int T, n, max_len;
    
        scanf("%d", &T);
    
        while(T--) {
            scanf("%d", &n);
            max_len = 0;
            m.clear();
    
            for(int i=0; i<n; i++) {
                cin >> s[i];
            }
    
            for(int i=0; i<N; i++) {
                for(int j=i+3-1; j<N; j++) {
                    if(j-i+1 < max_len) continue;
                    str = s[0].substr(i, j-i+1);
                    int k;
                    for(k=1; k<n; k++) {
                        if(s[k].find(str) == s[k].npos) {   //未找到
                            break;
                        }
                    }
    
                    if(k >= n && str.length() >= max_len) {    //找到
                        if(str.length() == max_len){
                            if(str < str_max) str_max = str;
                        }
                        else {
                            max_len = str.length();
                            str_max = str;
                        }
                    }
                }
            }
    
            if(max_len) cout << str_max << endl;
            else printf("no significant commonalities
    ");
        }
    
        return 0;
    }
  • 相关阅读:
    汤姆大叔的博客
    ajax
    兼容谷歌的光标居中写法
    浅谈服务治理与微服务
    Java线程面试题合集(含答案)
    java设计模式之装饰者模式
    java集合类详解
    java线程-看这一篇就够了
    javaIO详解
    java反射详解
  • 原文地址:https://www.cnblogs.com/tanhehe/p/3222951.html
Copyright © 2011-2022 走看看