fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. ios::sync_with_stdio(false);
  6. cin.tie(nullptr);
  7.  
  8. string x, y;
  9. while ( (cin >> x >> y) ) {
  10. if (y.size() < x.size()) {
  11. cout << "NO\n";
  12. continue;
  13. }
  14.  
  15. while (y.size() > x.size()) {
  16. if (y.back() == 'A') {
  17. y.pop_back();
  18. } else if (y.front() == 'B') {
  19. y.erase(y.begin());
  20. reverse(y.begin(), y.end());
  21. } else {
  22. break;
  23. }
  24. }
  25. cout << (y == x ? "YES\n" : "NO\n");
  26. }
  27. return 0;
  28. }
Success #stdin #stdout 0.01s 5324KB
stdin
A BABA
A ABBA
BAAAAABAA BAABAAAAAB
stdout
NO
NO
YES