fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define int long long
  5.  
  6. const long double PI = 3.14159265359;
  7.  
  8. void solve()
  9. {
  10. int n, m;
  11. cin >> n >> m;
  12. string p, q;
  13. cin >> p >> q;
  14. for (int i = 0; i < n; i++)
  15. {
  16. for (int j = 0; j < m; j++)
  17. {
  18. if (p[i] == q[j])
  19. {
  20. p[i] = '?', q[j] = '.';
  21. break;
  22. }
  23. }
  24. }
  25.  
  26. int s = 0, ic = 0, x = 0, total = 0;
  27. for (int i = 0; i < n; i++)
  28. {
  29. if (p[i] == 's')
  30. s++;
  31. if (p[i] == 'i')
  32. ic++;
  33. if (p[i] == 'x')
  34. x++;
  35. if (p[i] != '?')
  36. total++;
  37. }
  38.  
  39. if (total == 3 && s == 1 && x == 1 && ic == 1 && count(q.begin(), q.end(), '.') == m)
  40. cout << "YES" << '\n';
  41. else
  42. cout << "NO" << '\n';
  43. }
  44.  
  45. signed main(void)
  46. {
  47. ios_base::sync_with_stdio(0);
  48. cin.tie(0);
  49. cout.tie(0);
  50. if (fopen("input.txt", "r"))
  51. {
  52. freopen("input.txt", "r", stdin);
  53. freopen("output.txt", "w", stdout);
  54. }
  55. int t = 1;
  56. cin >> t;
  57. while (t--)
  58. {
  59. solve();
  60. }
  61. return 0;
  62. }
Success #stdin #stdout 0s 5320KB
stdin
5
4 1
sinx
n
6 7
xixsms
mixsxim
8 5
fixtures
frute
3 3
abc
def
5 10
sixty
codeforces
stdout
YES
NO
YES
NO
NO