fork(1) download
  1. #include <bits/stdc++.h>
  2.  
  3. #define fi "ASTRING.INP"
  4. #define fo "ASTRING.OUT"
  5.  
  6. #define ll long long
  7.  
  8. using namespace std;
  9.  
  10. int n, m;
  11. string a, b;
  12.  
  13. int main() {
  14. ios_base::sync_with_stdio(false);
  15. cin.tie(NULL); cout.tie(NULL);
  16.  
  17. cin >> n >> m;
  18. cin >> a;
  19. cin >> b;
  20.  
  21. int j = 0;
  22. for (int i = 0; i < n; i++) {
  23. while (a[i] != b[j] && j < m) j++;
  24. if (a[i] != b[j]) {
  25. cout << "N";
  26. return 0;
  27. }
  28. else j++;
  29. }
  30. cout << "Y";
  31. return 0;
  32. }
Success #stdin #stdout 0.01s 5268KB
stdin
3 
10 
ABC
CDACDBĐCA
stdout
Y