【题目链接】click here~~ 

【题目大意】: 

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 test(s) 

input 

ABA 

output 

NO 

input 

BACFAB 

output 

YES 

给出一行字符,推断是否出现两个不重叠的字串“AB”和“BA”

代码:

/*
str.find()函数
返回str在字符串中第一次出现的位置(从index開始查找)。假设没找到则返回string::npos,
返回str在字符串中第一次出现的位置(从index開始查找。长度为length)。 假设没找到就返回string::npos,
返回字符ch在字符串中第一次出现的位置(从index開始查找)。假设没找到就返回string::npos
*/
#include <bits/stdc++.h>
using namespace std;
string str;
int main()
{
cin>>str;
int len=str.size();
if(len<=3) puts("NO");
else
{
int a=str.find("AB");
int b=str.find("BA",a+2);
int c=str.find("BA");
int d=str.find("AB",c+2);
if(a!=-1&&b!=-1||c!=-1&&d!=-1) puts("YES");
else puts("NO");
}
return 0;
}
/*
strstr函数:查找字符串第一次出现的位置
*/
#include<bits/stdc++.h>
using namespace std;
char str[200000],*p;
int main()
{
cin>>str;
if((p=strstr(str,"AB")) && (strstr(p+2,"BA")))puts("YES");
else if((p=strstr(str,"BA")) && strstr(p+2,"AB"))puts("YES");
else puts("NO");
return 0;
}

CodeForces 550A Two Substrings(模拟)的更多相关文章

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

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

  2. Codeforces 626A Robot Sequence(模拟)

    A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...

  3. Codeforces 738D. Sea Battle 模拟

    D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...

  4. CodeForces - 589D(暴力+模拟)

    题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...

  5. Codeforces 767B. The Queue 模拟题

    B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...

  6. codeforces #271D Good Substrings

    原题链接:http://codeforces.com/problemset/problem/271/D 题目原文: D. Good Substrings time limit per test 2 s ...

  7. Codeforces 704A Thor 队列模拟

    题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...

  8. Codeforces 316G3 Good Substrings 字符串 SAM

    原文链接http://www.cnblogs.com/zhouzhendong/p/9010851.html 题目传送门 - Codeforces 316G3 题意 给定一个母串$s$,问母串$s$有 ...

  9. Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)

    大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...

随机推荐

  1. 简单使用CSS3实现炫酷读者墙效果

    读者墙,在很多网站上都有,没有遇到过的,可以参考度娘:读者墙http://www.baidu.com/s?wd=%B6%C1%D5%DF%C7%BD 使用基础的Html和CSS写出雏形 需要一提的是头 ...

  2. 九度 题目1421:Abor

    转载声明本文地址 http://blog.csdn.net/yangnanhai93/article/details/40563285 题目链接:http://ac.jobdu.com/problem ...

  3. scala多线程

    object Test { def main(args: Array[String]) { //创建线程池 val threadPool:ExecutorService=Executors.newFi ...

  4. 实战:INNOBACKUPEX for mysql 5.6自己主动还原脚本-v2

    脚本再次更新,共享一下! #!/bin/sh # # 用法: # ./restore.sh /你备份文件的全路径 #ocpyang@126.com INNOBACKUPEX=innobackupex ...

  5. 设置网站expires和max-age属性

    转:http://www.zicheng.net/article/982022.htm 在使用百度站长工具测试网站优化建议时,在 设置静态内容缓存时间 栏目里,会提示 类似 FAILED - (未设置 ...

  6. [Angular-Scaled web] 1. Architecture and file structure

    We build a project according to its features or based on simple MVC structure. Put all controller in ...

  7. 【pyhon】理想论坛爬虫1.07 退出问题,乱码问题至此解决,只是目前速度上还是遗憾点

    在 https://www.cnblogs.com/mengyu/p/6759671.html 的启示下,解决了乱码问题,在此向作者表示感谢. 至此,困扰我几天的乱码问题和退出问题都解决了,只是处理速 ...

  8. redis sentinel(哨兵机制)部署(Windows下实现)

    另外参考:http://www.cnblogs.com/LiZhiW/p/4851631.html 一.准备条件 1.操作系统:win7 2.redis版本:redis-2.8.19 二.下载Redi ...

  9. Android 之 AndroidManifest.xml 详解(一)

    当Android启动一个应用程序组件之前,它必须知道哪些个组件是存在的,所以开发人员在开发过程中,必须将应用程序中出现的组件一一在AndroidManifest.xml文件中" 声明 &qu ...

  10. 知识共享图文直播---(一)将数据库中的数据加载到MSFlexGrid空间中再导入Excel

    熟话说万物皆有其存在的道理,为什么我突然想写<知识共享图文直播>这个系列呢?首先,我想的是记录自己学习的历程,在记录中加深自己对知识的理解,同时也希望自己的博文能帮助到其他数据库的初学者. ...