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 ;
}

A - Two Substrings的更多相关文章

  1. [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  2. Leetcode: Unique Substrings in Wraparound String

    Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...

  3. CSU-1632 Repeated Substrings (后缀数组)

    Description String analysis often arises in applications from biology and chemistry, such as the stu ...

  4. CF451D Count Good Substrings (DP)

    Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...

  5. LA4671 K-neighbor substrings(FFT + 字符串Hash)

    题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...

  6. 后缀数组---New Distinct Substrings

    Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...

  7. Codeforces Round #258 D Count Good Substrings --计数

    题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...

  8. SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转

    694. Distinct Substrings Problem code: DISUBSTR   Given a string, we need to find the total number o ...

  9. Codeforces Round #306 (Div. 2) A. Two Substrings 水题

    A. Two Substrings Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/550/pro ...

  10. CF Two Substrings

    Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...

随机推荐

  1. 移动端日历选择控件(支持Zepto和JQuery)

    移动端日历选择控件(支持Zepto和JQuery) <!DOCTYPE html> <html> <head> <meta charset="utf ...

  2. decorate all function in all module

    需求: 有package db_api,其下有很多 module 如 plane.py ship.py ufo.py.这些module内定义了方法如 plane.fly(), ship.float() ...

  3. 使用uilabel重新自调整高度后显示横线和竖线问题

    这个使用uilabel自调节高度发现的问题,代码如下: //content label                        NSString *contentValue = ((Messag ...

  4. ubuntu 添加和删除用户

    Without a home directory sudo useradd myuser With home directory sudo useradd -m myuser Then set the ...

  5. 出现异常时直接把e输出比输出e.getMessage()好得多

    之前研究态度不好,出异常时处理草草了事,今天出现问题才觉得该认真对待每个分支.

  6. Android:图片中叠加文字,支持拖动改变位置

    之所以做了这么一个Demo,是由于近期项目中有一个奇葩的需求:用户拍摄照片后,分享到微信的同一时候加入备注,想获取用户在微信的弹出框输入的内容.保存在自己的server上.而其实,这个内容程序是无法获 ...

  7. PS 如何使用液化工具给人物减肥

    进入"液化", 有个收缩按钮, 可以选择范围大小, 想瘦哪里, 瘦多少都OK   最终效果图     1.打开原图,进入通道面板,选择菜单图像计算,计算红色通道,保留人物见图.   ...

  8. vimrc 避免中文乱码配置

    et smsyntax onset ts=4set sts=4set sw=4set hlsearchset rulerset backspace=indent,eol,startset encodi ...

  9. 1.shell编程之变量的高级用法

    1.1.变量替换 变量替换的六种形式 实例:非贪婪和贪婪的区别 从头部删除 [root@VM_0_9_centos shell_learn]# var_1="i love you,do yo ...

  10. 【手记】走近科学之为什么JObject不能调用LINQ扩展方法

    Json.NET的JObject明明实现了IEnumerable<T>,具体来说是IEnumerable<KeyValuePair<string, JToken>> ...