0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-28 13:31:59 +00:00

P3375 【模板】KMP字符串匹配

R67811368
This commit is contained in:
Baoshuo Ren 2022-01-24 20:41:50 +08:00
parent bbbe6dc6df
commit d4301084bc
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

32
Luogu/P3375/P3375.cpp Normal file
View File

@ -0,0 +1,32 @@
#include <iostream>
#include <string>
using std::cin;
using std::cout;
using std::endl;
int border[1000005];
std::string s1, s2;
int main() {
cin >> s1 >> s2;
for (int i = 0; i < s1.size(); i++) {
bool flag = false;
if (s1.substr(i, s2.size()) == s2) {
cout << i + 1 << endl;
}
}
for (int i = 0; i < s2.size(); i++) {
bool flag = false;
for (int j = i; j > 0; j--) {
if (s2.substr(0, j) == s2.substr(i - j + 1, j)) {
flag = true;
cout << j << ' ';
break;
}
}
if (!flag) cout << 0 << ' ';
}
cout << endl;
return 0;
}