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 ... 
随机推荐
- JS---数组(Array)处理函数整理
			1.concat() 连接两个或更多的数组该方法不会改变现有的数组,而仅仅会返回被连接数组的一个副本.例如: 代码如下: <script type="text/javascript&q ... 
- init.rc文件中面启动c++程序,通过jni调用java实现
			</pre><p>注:假设是自己的myself.jar包,还要修改例如以下:</p><p>target/product/core_base.mk PRO ... 
- Spring -- Bean自己主动装配&Bean之间关系&Bean的作用域
			对于学习spring有帮助的站点:http://jinnianshilongnian.iteye.com/blog/1482071 Bean的自己主动装配 Spring IOC 容器能够自己主动装配 ... 
- 让你的eclipse实现写JAVA代码,HTML,CSS,JAVASCRIPT代码提示
			1.打开eclipse→Windows→Preferences→Java→Editor→Content Assist 改动Auto Activation triggers for java的值为:zj ... 
- Spark Streaming性能优化系列-怎样获得和持续使用足够的集群计算资源?
			一:数据峰值的巨大影响 1. 数据确实不稳定,比如晚上的时候訪问流量特别大 2. 在处理的时候比如GC的时候耽误时间会产生delay延迟 二:Backpressure:数据的反压机制 基本思想:依据上 ... 
- const成员函数总结
			const 成员函数: 类的成员函数后面加 const,表明这个函数不会对这个类对象的数据成员(准确地说是非静态数据成员)作不论什么改变. 在设计类的时候.一个原则就是对于不改变数据成员的成员函数都要 ... 
- hdu 4858 项目管理(vector模拟)
			# include <stdio.h> # include <algorithm> # include <string.h> # include <vecto ... 
- openwrt 模拟i2c驱动(一)
			一:加载i2c driver kmod-i2c-core................................................ I2C support kmod-i2c-al ... 
- Highmaps的天津地图数据JSON格式
			Highmaps的天津地图数据JSON格式 Highmaps的天津地图数据JSON格式 下载链接: http://pan.baidu.com/s/1eQgxECU password: tjmj 天津地 ... 
- Android — 长按ListView 利用上下文菜单(ActionMode) 进行批量事件处理
			好久没写博客拉``````` 近期最终略微闲一点了``````` 无聊拿手机清理短信.发现批量事件的处理还是挺管用的`````` 那么自己也来山寨一记看看效果吧````` 闲话少说,首先,我们来看下手 ... 
