A - Two Substrings
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
InputABAOutputNOInputBACFABOutputYESInputAXBYBXAOutputNOHint
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的更多相关文章
- [LeetCode] Unique Substrings in Wraparound String 封装字符串中的独特子字符串
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- Leetcode: Unique Substrings in Wraparound String
Consider the string s to be the infinite wraparound string of "abcdefghijklmnopqrstuvwxyz" ...
- CSU-1632 Repeated Substrings (后缀数组)
Description String analysis often arises in applications from biology and chemistry, such as the stu ...
- CF451D Count Good Substrings (DP)
Codeforces Round #258 (Div. 2) Count Good Substrings D. Count Good Substrings time limit per test 2 ...
- LA4671 K-neighbor substrings(FFT + 字符串Hash)
题目 Source http://acm.hust.edu.cn/vjudge/problem/19225 Description The Hamming distance between two s ...
- 后缀数组---New Distinct Substrings
Description Given a string, we need to find the total number of its distinct substrings. Input T- nu ...
- Codeforces Round #258 D Count Good Substrings --计数
题意:由a和b构成的字符串,如果压缩后变成回文串就是Good字符串.问一个字符串有几个长度为偶数和奇数的Good字串. 分析:可知,因为只有a,b两个字母,所以压缩后肯定为..ababab..这种形式 ...
- SPOJ 694. Distinct Substrings (后缀数组不相同的子串的个数)转
694. Distinct Substrings Problem code: DISUBSTR Given a string, we need to find the total number o ...
- 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 ...
- CF Two Substrings
Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard inpu ...
随机推荐
- install Python 2.7 and Python 3.3 on CentOS 6
来自:http://toomuchdata.com/2014/02/16/how-to-install-python-on-centos/ In this guide I will show you ...
- Java8 本地DateTime API
原文:http://www.yiibai.com/java8/java8_localdateapi.html 使用Java8,新的日期时间API引入覆盖旧的日期时间API的以下缺点. 非线程安全 - ...
- 【powerdesign】从mysql数据库导出到powerdesign,生成数据字典
使用版本powerdesign16.5,mysql 5.5,windows 64 =========================================================== ...
- (CF)Codeforces445A DZY Loves Chessboard(纯实现题)
转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/pro ...
- linux批量解压和批量压缩
ls *.tar.gz | xargs -n1 tar xzvf //批量解压 ls | awk '{ print "tar zcvf "$0".tar.gz " ...
- hdu 1710 Binary Tree Traversals 前序遍历和中序推后序
题链;http://acm.hdu.edu.cn/showproblem.php?pid=1710 Binary Tree Traversals Time Limit: 1000/1000 MS (J ...
- 基于canvas和Web Audio的音频播放器
wavesurfer.js是一款基于HTML5 canvas和Web Audio的音频播放器插件.通过wavesurfer.js你能够使用它来制作各种HTML5音频播放器,它能够在各种支持 Web A ...
- python 字符串前缀
普通字符串 一般字符串都是已unicode编码,且和C类似,可以使用\来转义,比如 a = "test\ntest" print(a) 输出 test test 前面加r 在字符串 ...
- window.open() 父子页面的传值问题
if(window.opener){//判断是否有父窗口,即打开本页面的窗口 window.opener.location.reload();//刷新父窗口 window.op ...
- spring中构造函数注入
spring中构造函数注入,简单来说,就是通过beans.xml中,设置对应的值.而且通过bean类中的构造函数进行注入这些值. 文件结构 watermark/2/text/aHR0cDovL2Jsb ...