mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 17:56:28 +00:00
P3375 【模板】KMP字符串匹配
R67811368
This commit is contained in:
parent
bbbe6dc6df
commit
d4301084bc
32
Luogu/P3375/P3375.cpp
Normal file
32
Luogu/P3375/P3375.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user