fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {string s;
  7. bool x=0,y=0;
  8. cin>>s;
  9. for(int i=0;i<s.length();i++){
  10. if(s[i]=='A'&&s[i+1]=='B'){
  11. x=1;
  12. if(s[i+2]=='A')
  13. i+=3;
  14. }
  15. if(s[i]=='B'&&s[i+1]=='A'){
  16. y=1;
  17. if(s[i+2]=='B')
  18. i+=3;
  19. }}
  20. if(x&&y)
  21. cout<<"YES";
  22. else
  23. cout<<"NO";
  24. return 0;
  25. }
Success #stdin #stdout 0s 5464KB
stdin
BAAB
stdout
YES