StoneHaos

9

Nov 29th, 2021
827
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <string>
  3.  
  4. using namespace std;
  5.  
  6. int find(string s, string t) {
  7.     int i = -1;
  8.     int j = 0;
  9.     int n = s.size();
  10.     int m = t.size();
  11.     do {
  12.         j = 0;
  13.         i ++;
  14.         while (j < m && s[i + j] == t[j]) j++;
  15.     } while (j < m && i < n - m);
  16.     if (j == m) return i;
  17.     return -1;
  18. }
  19.  
  20. int main() {
  21.     string s, t;
  22.     cin >> s >> t;
  23.     cout << find(s, t) << endl;
  24.     return 0;
  25. }
RAW Paste Data