Advertisement
myLoveOnlyForYou

Untitled

Feb 18th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.89 KB | None | 0 0
  1.  
  2. #include <iostream>
  3. #include <string>
  4. #include <set>
  5. #include <algorithm>
  6. #include <iterator>
  7. using namespace std;
  8.  
  9. int main() {
  10. // freopen("input.txt", "r", stdin);
  11. // freopen("output.txt", "w", stdout);
  12. string str;
  13. cin >> str;
  14. int n; cin >> n;
  15. for (int h = 0; h < n; h++) {
  16. string substr;
  17. cin >> substr;
  18. int *pi = new int[substr.length()];
  19. pi[0] = 0;
  20. int j = 0, i = 1;
  21. while (i != substr.length()) {
  22. if (substr[i] == substr[j]) {
  23. pi[i] = j + 1;
  24. i++;
  25. j++;
  26. }
  27. else if (j == 0) {
  28. pi[i] = 0;
  29. i++;
  30. }
  31. else
  32. j = pi[j - 1];
  33. }
  34.  
  35. int k = 0, l = 0;
  36. while (l != str.length()){
  37. if (str[k] == substr[l]){
  38. k++; l++;
  39. if (l == str.length())
  40. cout << l << endl;
  41. }
  42. else if (l == 0){
  43. k++;
  44.  
  45. }
  46. }
  47. }
  48.  
  49. return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement