竞赛讨论区 > 牛客小白月赛19「水」悠悠碧波
头像
肥嘟嘟左卫门QAQ
发布于 2019-11-23 23:13
+ 关注

牛客小白月赛19「水」悠悠碧波

#include <bits/stdc++.h>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.size();
    string t;
    for(int i = 1; i <= n / 3; i++){
        string a = s.substr(0, i), b = s.substr(i, n - 2 * i), c = s.substr(n - i, i);
        if(a == c && b.find(a) != b.npos)
            t = a;
    }
    cout << t << endl;
    return 0;
}
有人能分析下上面这个代码的时间复杂度吗,另外substr函数和string的find函数的时间复杂度也说下。

全部评论

(0) 回帖
加载中...
话题 回帖

等你来战

查看全部

热门推荐