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. // Check if string t can be formed by removing characters from s
  17. bool canForm = false;
  18.  
  19. // Try to find substring of s that can match t
  20. for (int i = 0; i <= n - m; i++) {
  21. string sub = s.substr(i, m);
  22. if (sub == t) {
  23. canForm = true;
  24. break;
  25. }
  26. }
  27.  
  28. // Output result based on the check
  29. if (canForm) {
  30. cout << "YES" << endl;
  31. } else {
  32. cout << "NO" << endl;
  33. }
  34. }
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0.01s 5320KB
stdin
2
4 2
acdc
ad
4 2
accd
ad
stdout
NO
NO