fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. string txt, pat;
  7. cin >> txt;
  8. cin >> pat;
  9.  
  10. int m = pat.size();
  11. int n = txt.size();
  12. for (int i = 0; i <= n - m; i++) {
  13. int j;
  14. for (j = 0; j < m; j++) {
  15. if (txt[i + j] != pat[j]) {
  16. break;
  17. }
  18. }
  19. if (j == m) {
  20. cout << "Pattern found at index " << i << endl;
  21. }
  22. }
  23.  
  24. return 0;
  25. }
  26.  
  27.  
Success #stdin #stdout 0.01s 5280KB
stdin
Standard input is empty
stdout
Pattern found at index 0