调了2个晚上了,再调试不出来,我家长给收拾我了。 第三个点WA了,哪位大佬帮看看哪有问题啊!!!
#include <bits/stdc++.h>
using namespace std;
int f[1000001];
void get(int n, string s) {
f[0] = 0;
f[1] = 0;
for (int i = 1; i < n; ++i) {
int j = f[i];
while (j != 0 && s[j] != s[i]) {
j = f[j];
}
if (s[i] == s[j]) {
f[i + 1] = j + 1;
} else {
f[i + 1] = 0;
}
}
}
void best_coder() {
int n, m;
cin >> n;
string s, x, t;
cin >> s;
for (int i = 1; i < n; ++i) {
cin >> x;
m = s.size() + x.size();
t = x + s;
get(m, t);
for (int j = x.size(); j < m; ++j) {
if (!f[j + 1]) {
cout << t[j];
}
}
s = x;
}
for (int j = 0; j < x.size(); ++j) {
if (!f[j + 1]) {
cout << t[j];
}
}
}
void happy_coder() {
}
int main() {
// 提升cin、cout效率
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
// 小码匠
best_coder();
// 最优解
// happy_coder();
return 0;
}