fork download
  1. #include <iostream>
  2. #include <string>
  3. using namespace std;
  4.  
  5. bool isValid(string s, string t, int m, int n) {
  6. // Try to match t in s from any position
  7. for (int i = 0; i <= m - n; i++) {
  8. bool isMatch = true;
  9. for (int j = 0; j < n; j++) {
  10. if (s[i + j] != t[j] && s[i + j] != t[j] - 'a' + 'A' && s[i + j] != t[j] - 'A' + 'a') {
  11. isMatch = false;
  12. break;
  13. }
  14. }
  15. if (isMatch) return true;
  16. }
  17. return false;
  18. }
  19.  
  20. int main() {
  21. int T;
  22. cin >> T; // Number of test cases
  23.  
  24. while (T--) {
  25. int m, n;
  26. cin >> m >> n; // Length of the two strings
  27.  
  28. string s, t;
  29. cin >> s >> t; // The two strings
  30.  
  31. if (isValid(s, t, m, n)) {
  32. cout << "YES" << endl;
  33. } else {
  34. cout << "NO" << endl;
  35. }
  36. }
  37.  
  38. return 0;
  39. }
  40.  
  41.  
Success #stdin #stdout 0.01s 5316KB
stdin
2
4 2
acdc
ad
4 2
accd
ad
stdout
NO
NO