zoukankan      html  css  js  c++  java
  • poj3080

    枚举第一串的所有子串,看其他串是否也有

    View Code
    #include <iostream>
    #include
    <cstdlib>
    #include
    <cstring>
    #include
    <cstdio>
    using namespace std;

    #define maxn 11

    string st[maxn];
    int n;

    void input()
    {
    scanf(
    "%d", &n);
    getchar();
    for (int i = 0; i < n; i++)
    getline(cin, st[i]);
    }

    void work()
    {
    string ans = "";
    for (int j = st[0].length(); j >= 3; j--)
    {
    for (int i = 0; i + j - 1 < st[0].length(); i++)
    {
    string temp = st[0].substr(i, j);
    bool ok = true;
    for (int k = 1; k < n; k++)
    if (st[k].find(temp) == string::npos)
    {
    ok
    = false;
    break;
    }
    if (ok && (ans == "" || ans > temp))
    ans
    = temp;
    }
    if (ans != "")
    {
    cout
    << ans << endl;
    return;
    }
    }
    printf(
    "no significant commonalities\n");
    }

    int main()
    {
    //freopen("D:\\t.txt", "r", stdin);
    int t;
    scanf(
    "%d", &t);
    while (t--)
    {
    input();
    work();
    }
    return 0;
    }
  • 相关阅读:
    WC命令
    dcoker machine
    linux命令
    Valgrind 检测程序内存使用
    golang flag
    面试之---二叉树的遍历
    FFMpeg 版本错误
    C++中namespace的使用
    QT之QStatusBar
    建立ftp服务器和客户端
  • 原文地址:https://www.cnblogs.com/rainydays/p/1972228.html
Copyright © 2011-2022 走看看