fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. using namespace std;
  5. vector<char> temp ;
  6. void check_loop(vector<char> &s, vector<char> &t){
  7. if(s == t){cout << 1 << endl; exit(0);}
  8. if(s.size() >= t.size()){return ; }
  9. if(t.back() == 'A'){
  10. temp = t ;
  11. temp.pop_back() ;
  12. check_loop(s,temp) ;
  13. }
  14. if(t[0] == 'B'){
  15. temp = t;
  16. reverse(temp.begin(), temp.end()) ;
  17. t.pop_back() ;
  18. check_loop(s,temp) ;
  19. }
  20. }
  21. int main(){
  22. string k ; cin >> k ;
  23. vector<char> s(k.begin(), k.end()) ;
  24. string k2 ; cin >> k2 ;
  25. vector<char> t(k2.begin() , k2.end()) ;
  26. check_loop(s,t) ;
  27. cout << 0 << endl ;
  28. return 0;
  29. }
Success #stdin #stdout 0.01s 5284KB
stdin
A
BABA
stdout
0