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. while (y.size() > x.size()) {
  15. if (y.back() == 'A') {
  16. y.pop_back();
  17. } else if (y.front() == 'B') {
  18. y.erase(y.begin());
  19. reverse(y.begin(), y.end());
  20. } else {
  21. break;
  22. }
  23. }
  24. cout << (y == x ? "YES\n" : "NO\n");
  25. }
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5288KB
stdin
bba bbaaaa
stdout
NO