1 条题解
-
1
#include <bits/stdc++.h> using namespace std; string s, str; int ne[1000006]; int get(int x, char ch) { while (1) { if (str[x] == ch) return x + 1; if (!x) return 0; x = ne[x]; } } int main() { std::ios::sync_with_stdio(false); cin >> s >> str; int n = s.length(); int m = str.length(); ne[1] = 0; for (int i = 2; i <= m; ++i) ne[i] = get(ne[i - 1], str[i - 1]); int ans = 0, t = 0; for (int i = 0; i < n; ++i) { t = get(t, s[i]); if (t == m) ++ans; } cout << ans << endl; return 0; }
- 1
信息
- ID
- 5534
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 10
- 标签
- 递交数
- 1
- 已通过
- 1
- 上传者