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. vue 组件之间的自定义方法互相调用

    1,先定义一个中间通信文件js globalBus.js import Vue from 'vue'; export const globalBus = new Vue(); 2,A.vue组件的方法 ...

  2. C#中的类和继承

    公众号「DotNet学习交流」,分享学习DotNet的点滴. 类继承 通过继承我们可以定义一个新类,新类纳入一个已经声明的类并进行扩展. 可以使用一个已经存在的类作为新类的基础.已存在的类称为基类(b ...

  3. 面试题——为什么 Vue 中不要用 index 作为 key?(diff 算法详解)

    前言 在vue中使用v-for时需要,都会提示或要求使用  :key,有的的开发者会直接使用数组的 index 作为 key 的值,但不建议直接使用 index作为 key 的值,有时我们面试时也会遇 ...

  4. C/S结构用户界面设计

    C/S结构用户界面设计 [实验编号] 10003809547j  图形用户界面设计 [实验学时] 8学时 [实验环境] l 所需硬件环境为微机: l 所需软件环境为Microsoft Visual S ...

  5. 【Android】无法通过drawable下的selector类型改变背景颜色?

    举例 我在darwable目录下创建了selector文件,并设置了如下内容 <?xml version="1.0" encoding="utf-8"?& ...

  6. 【JMeter】使用nmon进行性能资源监控

    使用nmon进行性能资源监控 目录 使用nmon进行性能资源监控 一.前言 二.nmon的下载安装 1.查看系统信息 2.查看CPU信息 2.下载 3.解压 4.一个小问题 三.在性能测试时使用命令行 ...

  7. 目标检测工具安装使用--labelImg

    如果想要在深度学习中训练我们自己的模型,就得对图片进行标注.labelImg是一个超级方便的目标检测图片标注工具,打开图片后,只需用鼠标框出图片中的目标,并选择该目标的类别,便可以自动生成voc格式的 ...

  8. 江西财经大学第一届程序设计竞赛 I 题 小P和小Q

    题目链接:https://www.nowcoder.com/acm/contest/115/I 这题目要注意的是!!!pow函数前强制类型转换一定要float !!!一定要是float,double不 ...

  9. 性能集成监控系统exporter+Prometheus+Grafana

    Prometheus 是一个时序数据库,存数据 exporter是收集器,来收集被监控的数据,想要监控不同的内容,就使用不同的exporter,这个exporter应该放在被测服务器上,再把expor ...

  10. 从零玩转人脸识别验证-face

    title: 从零玩转人脸识别验证 date: 2022-05-15 21:05:52.974 updated: 2023-05-16 00:00:11.594 url: https://www.yb ...