fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void solve() {
  6.  
  7. string a, b;
  8.  
  9. cin >> a >> b;
  10.  
  11. if(a.length() > b.length() || 2 * a.length() < b.length() || a[0] != b[0]) {
  12.  
  13. cout << "NO" << endl;
  14.  
  15. return ;
  16.  
  17. }
  18.  
  19. vector<int> a_count, b_count;
  20.  
  21. int count = 1;
  22.  
  23. for(int i = 1; i < a.length(); i++) {
  24.  
  25. if(a[i] != a[i - 1]) {
  26.  
  27. a_count.push_back(count);
  28.  
  29. count = 1;
  30.  
  31. }
  32.  
  33. else {
  34.  
  35. count++;
  36.  
  37. }
  38.  
  39. }
  40.  
  41. a_count.push_back(count);
  42.  
  43. count = 1;
  44.  
  45. for(int i = 1; i < b.length(); i++) {
  46.  
  47. if(b[i] != b[i - 1]) {
  48.  
  49. b_count.push_back(count);
  50.  
  51. count = 1;
  52.  
  53. }
  54.  
  55. else {
  56.  
  57. count++;
  58.  
  59. }
  60.  
  61. }
  62.  
  63. b_count.push_back(count);
  64.  
  65. if(a_count.size() != b_count.size()) {
  66.  
  67. cout << "NO" << endl;
  68.  
  69. return ;
  70.  
  71. }
  72.  
  73. for(int i = 0; i < a_count.size(); i++) {
  74.  
  75. if(a_count[i] > b_count[i] || 2 * a_count[i] < b_count[i]) {
  76.  
  77. cout << "NO" << endl;
  78.  
  79. return ;
  80.  
  81. }
  82.  
  83. }
  84.  
  85. cout << "YES" << endl;
  86.  
  87. }
  88.  
  89. int main() {
  90.  
  91. ios_base::sync_with_stdio(false);
  92. cin.tie(0);
  93.  
  94. int t;
  95.  
  96. cin >> t;
  97.  
  98. while(t--) {
  99.  
  100. solve();
  101.  
  102. }
  103.  
  104. return 0;
  105.  
  106. }
Success #stdin #stdout 0.01s 5284KB
stdin
5
R
RR
LRLR
LRLR
LR
LLLR
LLLLLRL
LLLLRRLL
LLRLRLRRL
LLLRLRRLLRRRL
stdout
YES
YES
NO
NO
YES