Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <set>
- #include <algorithm>
- #include <iterator>
- using namespace std;
- int main() {
- // freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- string str;
- cin >> str;
- int n; cin >> n;
- for (int h = 0; h < n; h++) {
- string substr;
- cin >> substr;
- int *pi = new int[substr.length()];
- pi[0] = 0;
- int j = 0, i = 1;
- while (i != substr.length()) {
- if (substr[i] == substr[j]) {
- pi[i] = j + 1;
- i++;
- j++;
- }
- else if (j == 0) {
- pi[i] = 0;
- i++;
- }
- else
- j = pi[j - 1];
- }
- int k = 0, l = 0;
- while (l != str.length()){
- if (str[k] == substr[l]){
- k++; l++;
- if (l == str.length())
- cout << l << endl;
- }
- else if (l == 0){
- k++;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement