Untitled

 avatar
unknown
c_cpp
a month ago
1.1 kB
8
Indexable
// clang-format off
#include <bits/stdc++.h>
using namespace std;

#define FIN(x) freopen(x, "r", stdin)
#define FASTIO ios_base::sync_with_stdio(0); cin.tie(0)
#define SZ(x) (sizeof(x) / sizeof(*x))
#define endl '\n'
typedef long long ll;

template <typename T> void print(T &v) {
  for (auto x : v)
    cout << x << ' ';
  cout << endl;
}
// clang-format on

void solve() {
  string s1, s2;
  cin >> s1 >> s2;
  if ((s2.length() - s1.length()) % 2 != 0) {
    cout << "NO" << endl;
    return;
  }
  if (s2.length() < s1.length()) {
    cout << "NO" << endl;
    return;
  }

  int i = 0, j = 0;
  stack<char> st;
  auto take = [&]() {
    if (st.empty() || st.top() != s2[j])
      st.push(s2[j]);
    else
      st.pop();
    j++;
  };

  while (i < s1.length() && j < s2.length()) {
    if (st.empty() && s2[j] == s1[i]) {
      i++;
      j++;
    } else
      take();
  }
  if (i < s1.length()) {
    cout << "NO" << endl;
    return;
  }

  while (j < s2.length())
    take();

  cout << (st.empty() ? "YES" : "NO") << endl;
}
int main() {
  // FIN("input.txt");
  FASTIO;

  int t;
  cin >> t;
  while (t--)
    solve();

  return 0;
}
Editor is loading...
Leave a Comment