• 题解— blue jeans (KMP算法)


    题目链接:https://cn.vjudge.net/contest/388654#problem/A

    字符串匹配kmp模板题

    #include <iostream>
    #include <algorithm>
    #include <cstdlib>
    #include <cstring>
    #include <string.h>
    #include <string>
    #include <cmath>
    #include <vector>
    #include <queue>
    
    using namespace std;
    typedef long long ll;
    
    string s[15], strmax;
    
    int main()
    {
        int n;
        cin >> n;
        while (n--)
        {
            strmax = "";
            int m;
            cin >> m;
            for (int i = 0; i < m; i++)
            {
                cin >> s[i];
            }
            for (int i = 0; i <= 60; i++)
            {
                for (int j = 0; j <= 60; j++)
                {
                    int flag = 0;
                    string temp = s[0].substr(i, j);
                    for (int k = 1; k < m; k++)
                    {
                        if (s[k].find(temp) == string::npos)
                        {
                            flag = 1;
                            break;
                        }
                    }
                    if (!flag)
                    {
                        if (temp.size() > strmax.size())
                        {
                            strmax = temp;
                        }
                        else if (temp.size() == strmax.size() && temp < strmax)
                        {
                            strmax = temp;
                        }
                    }
                }
            }
            if (strmax.size() < 3) cout << "no significant commonalities" << endl;
            else cout << strmax << endl;
        }
        return 0;
    }
  • 相关阅读:
    leveldb实现类sql查询
    系统设计
    Code Complete
    工具 VSCode快捷键
    C/C++ extern
    C/C++ 宏字符串拼接
    【Java】字符串
    【Java】常用类-sysytem-math
    【Java】枚举
    【Java】内部类
  • 原文地址:https://www.cnblogs.com/zny0222/p/13544801.html
Copyright © 2020-2023  润新知