fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n, m;
  7. cin >> n >> m;
  8. string a, b;
  9. cin >> a >> b;
  10.  
  11. int i = 0;
  12. bool ok = true;
  13. for (int j = 0; j < m; j++) {
  14. if (i < n && a[i] == b[j]) {
  15. i++;
  16. }
  17. if (i == n) {
  18. cout << "YES\n";
  19. ok = false;
  20. break;
  21. }
  22. }
  23. if(ok == true){
  24. cout << "NO";
  25. }
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5316KB
stdin
Standard input is empty
stdout
NO