A - Two Substrings

You are given string s. Your task is to determine if the given strings 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 between1 and 105 consisting of uppercase Latin letters.

Output

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

Example

INPUT

ABA

OUTPUT

NO

INPUT

BACFAB

OUTPUT

YES

INPUT

AXBYBXA

OUTPUT

NO

Note

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”

思路:

暴力解就是了,看到标签是DP想了半天。最后发现直接用C++的find函数即可

#include<bits/stdc++.h>
using namespace std;
int main(){
string s;
cin >> s;
int a = s.find("AB");
int b = s.find("BA");
if (a != -1 && s.find("BA", a + 2) != -1 || b != -1 && s.find("AB", b + 2) != -1)
cout << "YES";
else
cout << "NO";
}

Problem 550A - Two Substrings的更多相关文章

  1. CodeForces 550A Two Substrings(模拟)

    [题目链接]click here~~  [题目大意]:  You are given string s. Your task is to determine if the given string s ...

  2. Codeforces Round #306 (Div. 2) 550A Two Substrings

    链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...

  3. UVALive - 6869 Repeated Substrings 后缀数组

    题目链接: http://acm.hust.edu.cn/vjudge/problem/113725 Repeated Substrings Time Limit: 3000MS 样例 sample ...

  4. POJ3415 Common Substrings —— 后缀数组 + 单调栈 公共子串个数

    题目链接:https://vjudge.net/problem/POJ-3415 Common Substrings Time Limit: 5000MS   Memory Limit: 65536K ...

  5. FFT初步学习小结

    FFT其实没什么需要特别了解的,了解下原理,(特别推荐算法导论上面的讲解),模板理解就行了.重在运用吧. 处理过程中要特别注意精度. 先上个练习的地址吧: http://vjudge.net/vjud ...

  6. scau 2015寒假训练

    并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...

  7. Codeforces Round #606 (Div. 1) Solution

    从这里开始 比赛目录 我菜爆了. Problem A As Simple as One and Two 我会 AC 自动机上 dp. one 和 two 删掉中间的字符,twone 删掉中间的 o. ...

  8. [LeetCode&Python] Problem 696. Count Binary Substrings

    Give a string s, count the number of non-empty (contiguous) substrings that have the same number of ...

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

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

  10. HDU5008 Boring String Problem(后缀数组 + 二分 + 线段树)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5008 Description In this problem, you are given ...

随机推荐

  1. 时间复杂度为 O(n^2) 的排序算法

    对于小规模数据,我们可以选用时间复杂度为 O(n2) 的排序算法.因为时间复杂度并不代表实际代码的执行时间,它省去了低阶.系数和常数,仅代表的增长趋势,所以在小规模数据情况下, O(n2) 的排序算法 ...

  2. wps表格怎么打印选中区域的内容?

    打印选中区域的内容,您可以按照以下步骤进行操作: 选择要打印的区域 打开 WPS 表格,在工作表中选择您希望打印的区域.您可以拖动鼠标或使用键盘中的方向键来选择单元格. 设置打印区域 一旦您选中了需要 ...

  3. java-图片添加水印

    前言:    需求:需要在图片中添加水印,防止盗用   优缺点:     优点:保护版权,防止盗用     缺点 可能会影响图片的视觉效果:如果水印过大或过醒目,可能会影响图片的视觉效果. 可能会增加 ...

  4. 前端学习-html-1

    html常用标签 h1-h6:标题 p:段落 strong/em: 对文本进行设置    strong--加粗,强调作用  比如:商品价格    em--斜体,对文本内容修饰成斜体 hr/br: hr ...

  5. WinForm遍历控件

    1 foreach (Control c in this.Controls) 2 { 3 if (c is TextBox) 4 ((TextBox)c).Text = "1111" ...

  6. 零基础 从 yolo8 入门计算机视觉超简单:物体识别、图像分类、轨迹追踪、姿势识别

    目录 安装 Ultralytics 训练 模型验证 预测 & 识别 导出 追踪 图像分割提取 分类 姿势识别 轨迹生成 Ultralytics YOLOv8 是备受好评的实时目标检测和图像分割 ...

  7. python学习笔记:python的字符串拼接效率分析

    问题的起因是因为在做LeetCode5714题的时候,对于字符串拼接使用了 ans = ans+s[i] 提交后超时了,改成 ans+=s[i] 就可以通过了,而且用c++好像也有这个问题,在此记录一 ...

  8. GaussDB(DWS)中的分布式死锁问题实践

    本文分享自华为云社区<GaussDB(DWS)中的分布式死锁问题实践>,作者: 他强由他强 . 1.什么是分布式死锁 分布式死锁是相对于单机死锁而言,一个事务块中的语句,可能会分散在集群里 ...

  9. 神经网络优化篇:详解其他正则化方法(Other regularization methods)

    其他正则化方法 除了\(L2\)正则化和随机失活(dropout)正则化,还有几种方法可以减少神经网络中的过拟合: 一.数据扩增 假设正在拟合猫咪图片分类器,如果想通过扩增训练数据来解决过拟合,但扩增 ...

  10. Calico IPIP模式下的Cross Subnet特性分析

    本文分享自华为云社区<Calico IPIP模式下的CrossSubnet特性分析>,作者: 可以交个朋友. Calico ipip crossSubnet 模式 Calico-ipip模 ...