Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u

Description

You are given string s. Your task is to determine if the given string s contains two non-overlapping substrings "AB" and "BA" (the substrings can go in any order).

Input

The only line of input contains a string s of length between 1 and 105 consisting of uppercase Latin letters.

Output

Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.

Sample Input

Input
ABA
Output
NO
Input
BACFAB
Output
YES
Input
AXBYBXA
Output
NO

Hint

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".

题意:

给定一字符串,求能否找出“AB”“BA”两不重叠字符串。

啊啊啊,坑比的字符串题!!卡了三组数据TAT

附AC代码:

 #include<iostream>
#include<cstring>
using namespace std; int main(){
string s;
int t=-,v=-,ans,temp,x,y,a,b,c,d;
cin>>s;
int len=s.size();
ans=;
temp=;
x=;
y=;
for(int i=;i<len;i++){
if(s[i]=='A'&&s[i+]=='B'){
if(i!=t&&!ans){
ans++;
t=i+;
a=i;
break;
}
}
}
for(int i=;i<len;i++){
if(s[i]=='B'&&s[i+]=='A'){
if(i!=t&&i+!=a&&!temp){
temp++;
t=i+;
break;
}
}
}
for(int i=;i<len;i++){
if(s[i]=='B'&&s[i+]=='A'){
if(i!=v&&!x){
x++;
v=i+;
b=i;
break;
}
}
}
for(int i=;i<len;i++){
if(s[i]=='A'&&s[i+]=='B'){
if(i!=v&&i+!=b&&!y){
y++;
v=i+;
break;
}
}
}
if(ans&&temp){
cout<<"YES"<<endl;
return ;
}
else if(x&&y){
cout<<"YES"<<endl;
return ;
}
cout<<"NO"<<endl;
return ;
}

最新文章

  1. 【微框架】Maven +SpringBoot 集成 阿里大鱼 短信接口详解与Demo
  2. .Net语言 APP开发平台——Smobiler学习日志:快速实现应用中的图片、声音等文件上传功能
  3. Web之路笔记之一
  4. [AS3.0] NetConnection.Connect.Rejected 解决办法
  5. 构建自己的PHP框架--抽象框架的内容
  6. 新手入门之GDB调试
  7. LoadRunner在移动端性能测试的应用
  8. 洛谷P1134 阶乘问题
  9. POJ 1321 棋盘问题 --- DFS
  10. SQL Server如何使用XML格式传输解析
  11. 设计模式19---设计模式之状态模式(State)(行为型)
  12. 让 SpringMVC 接收多个对象的4种方法
  13. Spring学习(3)---Spring设值注入和构造注入
  14. 《程序设计入门——C语言》翁恺老师 第二周编程练习记录
  15. React组件通信技巧
  16. 001_ASP.NET MVC 实用教程 论坛项目 北盟网校 原创视频教程
  17. Linux内核启动分析笔记
  18. npm配置镜像、设置代理
  19. STS或eclipse安装SVN插件
  20. Mybatis笔记六:Mybatis中SqlSessionFactoryBuilder/SqlSessionFactory/SqlSession/映射器实例的作用域(Scope)和生命周期

热门文章

  1. 关于Lisp和函数式编程 &amp; 各种语言对比 &amp; TIOBE
  2. Solidworks如何运行Toolbox
  3. 分析Cocos2d-x横版ACT手游源码 1、公共
  4. C# json反序列化 对象中嵌套数组 (转载) 可能会导致循环或多重级联路径。请指定 ON DELETE NO ACTION 或 ON UPDATE NO ACTION,或修改其他 FOREIGN KEY 约束。
  5. ucgui界面设计演示样例2
  6. find the longest of the shortest (hdu 1595 SPFA+枚举)
  7. linux 输入子系统(4) intput_dev 接口描述
  8. Creating a .bash_profile on your mac
  9. Android 通过Application 传递数据
  10. set -- $variable