fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define ull unsigned long long
  7. #define initial first
  8. #define added second
  9. #define sort_all(v) sort(v.begin(), v.end())
  10.  
  11. #define ya_sayed_ya_badawy \
  12.   ios_base::sync_with_stdio(false); \
  13.   cin.tie(NULL);
  14.  
  15. const int MAX = 1e5 + 50;
  16. const int MOD = 1e9 + 7;
  17. const int OO = 1e9;
  18. const double EPS = (double)1e-9;
  19.  
  20. void solve()
  21. {
  22.  
  23. string p, s;
  24. cin >> p >> s;
  25.  
  26. int n1 = (int)p.size();
  27. int n2 = (int)s.size();
  28.  
  29. vector<int> frq;
  30. string ch = "";
  31.  
  32. frq.push_back(1);
  33. ch.push_back(p[0]);
  34.  
  35. int i = 1;
  36.  
  37. while (i < n1)
  38. {
  39. if (p[i] == p[i - 1])
  40. {
  41. frq[(int)frq.size() - 1]++;
  42. }
  43. else
  44. {
  45. ch.push_back(p[i]);
  46. frq.push_back(1);
  47. }
  48. i++;
  49. }
  50.  
  51. vector<int> frq2;
  52. string ch2 = "";
  53.  
  54. frq2.push_back(1);
  55. ch2.push_back(s[0]);
  56.  
  57. i = 1;
  58.  
  59. while (i < n2)
  60. {
  61. if (s[i] == s[i - 1])
  62. {
  63. frq2[(int)frq2.size() - 1]++;
  64. }
  65. else
  66. {
  67. ch2.push_back(s[i]);
  68. frq2.push_back(1);
  69. }
  70. i++;
  71. }
  72.  
  73. if ((int)ch.size() != (int)ch2.size())
  74. {
  75. cout << "NO";
  76. return;
  77. }
  78.  
  79. for (int i = 0; i < (int)ch.size(); i++)
  80. {
  81. if (frq2[i] < frq[i] || frq2[i] > 2 * frq[i])
  82. {
  83. cout << "NO";
  84. return;
  85. }
  86.  
  87. if (ch[i] != ch2[i])
  88. {
  89. cout << "NO";
  90. return;
  91. }
  92. }
  93.  
  94. cout << "YES";
  95. }
  96.  
  97. signed main()
  98. {
  99. ya_sayed_ya_badawy int t = 1;
  100. cin >> t;
  101.  
  102. while (t--)
  103. {
  104. solve();
  105. cout << endl;
  106. }
  107. return 0;
  108. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
YES