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 ...
随机推荐
- 【kotlin】报错:required:LIst<XXX> found:List<Unit>此类型的问题
出现问题如下: 解决方式如下: 解决思路:上面报出来的错误很明显,就是说想要的是List<XXX>类型但是给的却是List<Unit>类型,给的不是它想要的嘛 关键就是解决问题 ...
- js如何获取table或者ul中鼠标点的行号和内容
<html> <head> <script language="javascript"> function doclick() { var td ...
- Python机器学习--手写体识别(KNN+MLP)
MLP实现 调整参数比较性能结果 # -*- coding: utf-8 -*- """ Created on Wed Aug 30 21:14:38 2017 @aut ...
- [Testing] Config jest to test Javascript Application -- Part 2
Setup an afterEach Test Hook for all tests with Jest setupTestFrameworkScriptFile With our current t ...
- jQuery开发之Ajax
1.load()方法 (1)load()方法是jQuery中最经常使用和最简单的Ajax方法,能载入远程HTML代码,并插入代码中. 它的结构为: load(url [,data] [,callbac ...
- android存储訪问框架Storage Access Framework
在了解storage access framework之前.我们先来看看android4.4中的一个特性.假设我们希望能选择android手机中的一张图片,通常都是发送一个Intent给对应的程序.一 ...
- eclipse Kepler tomcat内存溢出解决方式
使用eclipse开发ssh项目,本机8G内存,可是在打开一个表格后再打开一个页面.立即就内存溢出,网上搜到下面解决方式,未解决: 1.改动eclipse.ini參数 -vmargs -Xms1024 ...
- 全文索引--自己定义chinese_lexer词典
本文来具体解释一下怎样自己定义chinese_lexer此法分析器的词典 初始化数据 create table test2 (str1 varchar2(2000),str2varchar2(2000 ...
- 【Unity 3D 游戏开发】Unity3D 入门 - 工作区域介绍 与 入门演示样例
一. 工作区域具体解释 1. Scence视图 (场景设计面板) scence视图简单介绍 : 展示创建的游戏对象, 能够对全部的游戏对象进行 移动, 操作 和 放置; -- 演示样例 : 创建一个球 ...
- Python调用C/Fortran混合的动态链接库--中篇
接下来,介绍一个简单的例子,从fortran中传递并返回一维自定义结构体数组到python注意点:1.fortran新标准支持可分配数组作为变量传入并在subroutine或function分配后返回 ...