mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:48:48 +00:00
parent
d7c1104f8b
commit
17e280db2a
@ -3,32 +3,41 @@
|
|||||||
|
|
||||||
using std::cin;
|
using std::cin;
|
||||||
using std::cout;
|
using std::cout;
|
||||||
using std::endl;
|
const char endl = '\n';
|
||||||
|
|
||||||
const int N = 1000005;
|
const int N = 1e6 + 5;
|
||||||
|
|
||||||
int f[N], next[N];
|
int next[N], f[N];
|
||||||
std::string s1, s2;
|
std::string s1, s2;
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
|
std::ios::sync_with_stdio(false);
|
||||||
|
cin.tie(nullptr);
|
||||||
|
|
||||||
cin >> s1 >> s2;
|
cin >> s1 >> s2;
|
||||||
|
|
||||||
next[0] = -1;
|
next[0] = -1;
|
||||||
|
|
||||||
for (int i = 1, j = -1; i < s2.size(); i++) {
|
for (int i = 1, j = -1; i < s2.size(); i++) {
|
||||||
while (j != -1 && s2[i] != s2[j + 1]) j = next[j];
|
while (~j && s2[i] != s2[j + 1]) j = next[j];
|
||||||
if (s2[i] == s2[j + 1]) j++;
|
if (s2[i] == s2[j + 1]) j++;
|
||||||
next[i] = j;
|
next[i] = j;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0, j = -1; i < s1.size(); i++) {
|
for (int i = 0, j = -1; i < s1.size(); i++) {
|
||||||
while (j != -1 && (j == s2.size() || s1[i] != s2[j + 1])) j = next[j];
|
while (~j && (j == s2.size() || s1[i] != s2[j + 1])) j = next[j];
|
||||||
if (s1[i] == s2[j + 1]) j++;
|
if (s1[i] == s2[j + 1]) j++;
|
||||||
if (j == s2.size() - 1) {
|
if (j + 1 == s2.size()) {
|
||||||
cout << i - j + 1 << endl;
|
cout << i - j + 1 << endl;
|
||||||
f[i] = j;
|
f[i] = j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < s2.size(); i++) {
|
for (int i = 0; i < s2.size(); i++) {
|
||||||
cout << next[i] + 1 << ' ';
|
cout << next[i] + 1 << ' ';
|
||||||
}
|
}
|
||||||
|
|
||||||
cout << endl;
|
cout << endl;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user