From d4301084bc734bc0d7a393e3fafc9c23eb352a1e Mon Sep 17 00:00:00 2001 From: Baoshuo Ren Date: Mon, 24 Jan 2022 20:41:50 +0800 Subject: [PATCH] =?UTF-8?q?P3375=20=E3=80=90=E6=A8=A1=E6=9D=BF=E3=80=91KMP?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=E5=8C=B9=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit R67811368 --- Luogu/P3375/P3375.cpp | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 Luogu/P3375/P3375.cpp diff --git a/Luogu/P3375/P3375.cpp b/Luogu/P3375/P3375.cpp new file mode 100644 index 00000000..55233b19 --- /dev/null +++ b/Luogu/P3375/P3375.cpp @@ -0,0 +1,32 @@ +#include +#include + +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; +}