Problem 550A - Two Substrings
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的更多相关文章
- CodeForces 550A Two Substrings(模拟)
[题目链接]click here~~ [题目大意]: You are given string s. Your task is to determine if the given string s ...
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
- UVALive - 6869 Repeated Substrings 后缀数组
题目链接: http://acm.hust.edu.cn/vjudge/problem/113725 Repeated Substrings Time Limit: 3000MS 样例 sample ...
- POJ3415 Common Substrings —— 后缀数组 + 单调栈 公共子串个数
题目链接:https://vjudge.net/problem/POJ-3415 Common Substrings Time Limit: 5000MS Memory Limit: 65536K ...
- FFT初步学习小结
FFT其实没什么需要特别了解的,了解下原理,(特别推荐算法导论上面的讲解),模板理解就行了.重在运用吧. 处理过程中要特别注意精度. 先上个练习的地址吧: http://vjudge.net/vjud ...
- scau 2015寒假训练
并不是很正规的.每个人自愿参与自愿退出,马哥找题(马哥超nice么么哒). 放假第一周与放假结束前一周 2015-01-26 http://acm.hust.edu.cn/vjudge/contest ...
- Codeforces Round #606 (Div. 1) Solution
从这里开始 比赛目录 我菜爆了. Problem A As Simple as One and Two 我会 AC 自动机上 dp. one 和 two 删掉中间的字符,twone 删掉中间的 o. ...
- [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 ...
- CSU-1632 Repeated Substrings (后缀数组)
Description String analysis often arises in applications from biology and chemistry, such as the stu ...
- HDU5008 Boring String Problem(后缀数组 + 二分 + 线段树)
题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5008 Description In this problem, you are given ...
随机推荐
- Cadence SPB 22.1 -- 原理图的电器元件放置03Day
1.新增原理图:"SCHEMATIC"-->"New Page" 2.元器件放置 ①.添加原理图库 ②.放置元器件 选择对应元件库,再选择需要放置的元件, ...
- Go语言函数详解
函数 (1)函数的定义 函数使用func进行定义 函数是基本的代码块,用于执行一个任务 Go语言至少有一个main函数 函数声明告诉了编译器函数的名称,返回类型和参数 //1.无参数无返回值函数的定义 ...
- jvm的jshell,学生的工具
jshell 在我眼里,只能作为学校教学的一个玩具,事实上官方也做了解释,以下是官方的解释: 在学习编程语言时,即时反馈很重要,并且 它的 API.学校引用远离Java的首要原因 教学语言是其他语言 ...
- [ABC262E] Red and Blue Graph
Problem Statement You are given a simple undirected graph with $N$ vertices and $M$ edges. The verti ...
- mybatis_高级
注解方式: 不需要配置文件 @select等注解直接放在接口mapper里 多表操作: @Select("select * from user1") @Results({ @Res ...
- 国产化软件新浪潮: spring 改造替代...
中午看了篇<国产化软件新浪潮:jdk redis mysql tomcat nginx改造替代品及信创名录> 想给它补充个 spring 改造替代:) 七.Spring 替代品 - Sol ...
- 一个Servlet如何实现增-删-改-查的业务逻辑
一.业务场景 最近在教学生学习JavaWeb中的Servlet,它就是一个Java服务端的小程序,用来提供各种服务. 在讲解得时候,自己突然遇到一个问题,那就是现在没有使用什么SpringMvc框架, ...
- 内核模块(.ko) 开发入门
内核模块时指的是在操作系统内核中动态加载的一段代码,它可以扩展和增强操作系统的功能.内核模块通常用于为操作系统添加新的设备驱动程序.文件系统.网络协议栈等功能. 内核模块是以二进制形式存在的(*.ko ...
- 有意思,我的GitHub账号值$23806.2,快来试试你的?
睡不着,看到一个有意思的网站:Estimate Github Worth Generator. 它可以用来估算 GitHub 账号的价值.马上试了一下. 我的账号估值:$23806.2 操作很简单,点 ...
- JavaFx之SceneBuilder添加其他依赖库(十六)
JavaFx之SceneBuilder添加其他依赖库(十六) Could not open 'xxxxx.jar' Open operation has failed. Make sure that ...