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 ...
随机推荐
- Git 安装与配置教程
一.下载Git 1.官网地址 下载地址 2.下载 二.安装 1.下载完成后,直接点击安装包安装,即可. 2.开始安装,然后下一步 3.可以在此处自定义地址,然后下一步 3.选择组件 此处默认即可,但我 ...
- .NET8极致性能优化AOT
前言 .NET8对于性能的优化是方方面面的,所以AOT预编译机器码也是不例外的.本篇来看下对于AOT的优化.原文:.NET8极致性能优化AOT 详述 首先明确一个概念,.NET里面的AOT它是原生的. ...
- .NET企业应用安全开发动向-概览
太长不读版:试图从安全的全局视角触发,探讨安全的重要性,讨论如何识别安全问题的方法,介绍.NET提供的与安全相关的基础设施,以及一些与时俱进的安全问题,为读者建立体系化的安全思考框架. 引言 关于&q ...
- LeetCode15:三数之和(双指针)
解题思路:常规解法很容易想到O(n^3)的解法,但是,n最大为1000,很显然会超时. 如何优化到O(n^2),a+b+c =0,我们只需要判断 a+b的相反数是否在数组中出现,而且元素的取值范围在 ...
- 深度解析 PyTorch Autograd:从原理到实践
本文深入探讨了 PyTorch 中 Autograd 的核心原理和功能.从基本概念.Tensor 与 Autograd 的交互,到计算图的构建和管理,再到反向传播和梯度计算的细节,最后涵盖了 Auto ...
- f-VAEGAN-D2:VAE+GAN处理零样本学习问题
虽然f-VAEGAN-D2在题目中说"适用任意样本",但对比的Few-shot相关的实验较少,这里仅讨论零样本学习的情况. 1. 背景介绍 由于为每个对象收集足够数量的高质量带标签 ...
- 放弃JavaFx开发学习
放弃JavaFx开发学习 一开始学学习JavaFx是想用java写个小游戏,后来学者JavaFx越来越深,发现坑也越来越多,不禁感叹:JavaFx果然是要抛弃的UI玩儿,UI开发还是用react na ...
- JNA入门(一)
JNA入门,代码在github写得明明白白:https://github.com/java-native-access/jna/blob/master/www/GettingStarted.md 一. ...
- Spring源码学习笔记6——Spring bean的实例化
一丶前言 前面我们了解到读取xml or 根据扫描路径生成BeanDefinition并注册到BeanFactory,相当于我们具备了生火做饭的原材料:BeanDefinition,接下来就是Spri ...
- 快速入门Mybatis完成基本CURD(注解实现)
一.什么是Mybatis? MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射. MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集. MyB ...