Loading... ```cpp #include<bits/stdc++.h> using namespace std; const int N = 100, M = 1000; int n, m; char p[N], s[M]; int ne[N]; int main(){ cin >> n >> p + 1 >> m >> s + 1; for(int i = 2, j = 0; i <= n; i++){ while(j && p[i] != p[j + 1]) j = ne[j]; if(p[i] == p[j + 1]) j++; ne[i] = j; } for(int i = 1, j = 0; i <= m; i++){ while(j && s[i] != p[j + 1]) j = ne[j]; if(s[i] == p[j + 1]) j++; if(j == n){ printf("%d", i - n); break; } } return 0; } ``` Last modification:January 30, 2023 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed