Advertisement
Guest User

Untitled

a guest
Jan 19th, 2020
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main()
  5. {
  6. int n;
  7. cin >> n;
  8.  
  9. while (n--)
  10. {
  11. int f = 0;
  12. string a, b, s;
  13.  
  14. cin >> a >> b;
  15.  
  16. string s1 = a;
  17. string s2 = b;
  18.  
  19. sort(a.begin(), a.end());
  20. sort(b.begin(), b.end());
  21.  
  22. if (a == b and a.size() == b.size())
  23. {
  24. cout << "YES" << endl;
  25. continue;
  26. }
  27.  
  28. else if (a.size() > b.size())
  29. {
  30. cout << "NO" << endl;
  31. continue;
  32. }
  33.  
  34. for (int i = 0; i <= s2.size() - s1.size(); i++)
  35. {
  36. s = s2.substr(i, s1.size());
  37.  
  38. sort(s.begin(), s.end());
  39.  
  40. if (a == s)
  41. {
  42. f = 1;
  43. break;
  44. }
  45. }
  46.  
  47. if (f)
  48. cout << "YES" << endl;
  49. else
  50. cout << "NO" << endl;
  51. }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement