fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. void solve(){
  16. string s,t,str;
  17. cin >> s >> t;
  18.  
  19. map<char,int>freq;
  20. for(char c : s){
  21. freq[c]++;
  22. }
  23.  
  24. vector<int> indexes;
  25.  
  26. for(char c : t){
  27. int index;
  28. if(freq[c] > 0){
  29. int cnt = freq[c];
  30. for(int j = 0; j < s.size(); j++){
  31. if(c == s[j]){
  32. if(cnt == 1){
  33. index = j;
  34. break;
  35. }
  36. else
  37. --cnt;
  38. }
  39. }
  40. indexes.push_back(index);
  41. freq[c]--;
  42. }
  43. else{
  44. no
  45. return;
  46. }
  47. }
  48.  
  49. string ans;
  50. for(int indexe : indexes){
  51. ans += s[indexe];
  52. }
  53.  
  54. if(ans == t) yes
  55. else no
  56.  
  57. }
  58.  
  59.  
  60. signed main(){
  61. FastIO();
  62.  
  63. int t = 1;
  64. cin >> t;
  65.  
  66. while (t--){
  67. solve();
  68. }
  69. return 0;
  70. }
  71.  
Success #stdin #stdout 0.01s 5264KB
stdin
6
DETERMINED TRME
DETERMINED TERM
PSEUDOPSEUDOHYPOPARATHYROIDISM PEPA
DEINSTITUTIONALIZATION DONATION
CONTEST CODE
SOLUTION SOLUTION
stdout
YES
YES
YES
YES
NO
YES