A. Two Substrings

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/550/problem/A

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

ABA

Sample Output

NO

HINT

题意

判断字符串是否存在不重合的AB和BA

题解:

虽然是一道傻逼题,但是被cha的人很多

我提供两组数据ABACCAB 和ABAB

这两组数据,来感受一下~

代码:

//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define test freopen("test.txt","r",stdin)
#define maxn 2000001
#define mod 10007
#define eps 1e-9
int Num;
char CH[];
const int inf=0x3f3f3f3f;
const ll infll = 0x3f3f3f3f3f3f3f3fLL;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
inline void P(int x)
{
Num=;if(!x){putchar('');puts("");return;}
while(x>)CH[++Num]=x%,x/=;
while(Num)putchar(CH[Num--]+);
puts("");
}
//************************************************************************************** int main()
{
//test;
string s;
string s1;
cin>>s;
s1=s;
int flag=;
int n=s.size();
for(int i=;i<n-;i++)
{
if(s1[i]=='B'&&s1[i+]=='A')
{
flag=,s1[i]='#',s1[i+]='#';
break;
}
}
if(flag==)
{
for(int i=;i<n-;i++)
{
if(s1[i]=='A'&&s1[i+]=='B')
{
cout<<"YES"<<endl;
return ;
}
}
}
s1=s;
flag=;
for(int i=;i<n-;i++)
{
if(s1[i]=='A'&&s1[i+]=='B')
{
flag=,s1[i]='#',s1[i+]='#';
break;
}
}
if(flag==)
{
for(int i=;i<n-;i++)
{
if(s1[i]=='B'&&s1[i+]=='A')
{
cout<<"YES"<<endl;
return ;
}
}
}
cout<<"NO"<<endl;
return ;
}

Codeforces Round #306 (Div. 2) A. Two Substrings 水题的更多相关文章

  1. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题

    A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...

  4. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  5. Codeforces Round #306 (Div. 2) 550A Two Substrings

    链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...

  6. Codeforces Round #306 (Div. 2) A. Two Substrings【字符串/判断所给的字符串中是否包含不重叠的“BA” “AB”两个字符串】

    A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...

  7. Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题

    A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...

  8. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  9. Codeforces Round #335 (Div. 2) B. Testing Robots 水题

    B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...

随机推荐

  1. Java并发编程-synchronized

    多线程的同步机制对资源进行加锁,使得在同一个时间,只有一个线程可以进行操作,同步用以解决多个线程同时访问时可能出现的问题.同步机制可以使用synchronized关键字实现.synchronized关 ...

  2. Linux系统上安装Python

    1.下载Python安装包,官网下:http://www.python.org/getit/ http://jingyan.baidu.com/article/eae07827f7f2d01fec54 ...

  3. Nodejs_day02

    Nodejs的事件模块 var events = require('events'); var eventEmitter = new events.EventEmitter();//创建EventEm ...

  4. jQuery文档加载完毕的几种写法

    js中文档加载完毕.一般在body加一个onload事件或者window.onload = function () {} jQuery中有好多写法,平时也不注意,别人一问,还真觉得头大. 下面是我整理 ...

  5. ShellExecute的各种用法

    一.利用系统默认的邮件收发器发送电子邮件 Uses ..., ShellAPI; Var lpHwnd: HWND; lpOperation, lpFile, lpParameters, lpDire ...

  6. NServiceBus教程-持久化

    NServiceBus的各种特性需要持久性.其中有超时.传奇和订阅存储. 四个持久化技术在NServiceBus在使用: RavenDB nHibernate 内存中 MSMQ 读到安装Raven D ...

  7. component to string

    component to string string to component ObjectTextToBinary ObjectBinaryToText ReadComponent #include ...

  8. HDU 5861 Road (线段树)

    Road 题目链接: http://acm.split.hdu.edu.cn/showproblem.php?pid=5861 Description There are n villages alo ...

  9. C++11之sizeof

    [C++11之sizeof] 在标准C++,sizeof可以作用在对象以及类别上.但是不能够做以下的事: 这会传回OtherType的大小.C++03并不允许这样做,所以会引发编译错误.C++11将会 ...

  10. 新 esb-cs-tool.jar 参数说明

    旧esb-cs-tool.jar 使用说明 : invoke(RequestBusinessObject requestBo) 旧参数说明: requestBo  : 封装好的请求参数大对象  Req ...