fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool canBeMadeEqual(const string& s, const string& t) {
  6. int i = 0, j = 0;
  7.  
  8. // 尝试在 s 中匹配 t
  9. while (i < s.size() && j < t.size()) {
  10. if (s[i] == t[j]) {
  11. j++;
  12. }
  13. i++;
  14. }
  15.  
  16. return j == t.size(); // 如果完全匹配 t,则返回 true
  17. }
  18.  
  19. int main() {
  20. int T;
  21. cin >> T;
  22.  
  23. while (T--) {
  24. int m, n;
  25. cin >> m >> n;
  26. string s, t;
  27. cin >> s >> t;
  28.  
  29. if (canBeMadeEqual(s, t)) {
  30. cout << "YES" << endl;
  31. } else {
  32. cout << "NO" << endl;
  33. }
  34. }
  35.  
  36. return 0;
  37. }
  38.  
Success #stdin #stdout 0s 5316KB
stdin
2
4 2
acdc
ad
4 2
accd
ad
stdout
YES
YES