fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. int main() {
  6. int T; // Number of test cases
  7. cin >> T;
  8.  
  9. while (T--) {
  10. int n, m;
  11. string s, t;
  12.  
  13. cin >> n >> m; // Lengths of strings s and t
  14. cin >> s >> t; // Strings s and t
  15.  
  16. int i = 0, j = 0;
  17. while (i < n && j < m) {
  18. if (s[i] == t[j]) {
  19. j++; // Move to the next character in t
  20. }
  21. i++; // Always move to the next character in s
  22. }
  23.  
  24. // If we've matched all characters of t
  25. if (j == m) {
  26. cout << "YES" << endl;
  27. } else {
  28. cout << "NO" << endl;
  29. }
  30. }
  31.  
  32. return 0;
  33. }
  34.  
Success #stdin #stdout 0.01s 5320KB
stdin
2
4 2
acdc
ad
4 2
accd
ad
stdout
YES
YES