牛客小白月赛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函数的时间复杂度也说下。
查看13道真题和解析