CodeForces 550A Two Substrings(模拟)
【题目链接】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(模拟)的更多相关文章
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
- Codeforces 626A Robot Sequence(模拟)
A. Robot Sequence time limit per test:2 seconds memory limit per test:256 megabytes input:standard i ...
- Codeforces 738D. Sea Battle 模拟
D. Sea Battle time limit per test: 1 second memory limit per test :256 megabytes input: standard inp ...
- CodeForces - 589D(暴力+模拟)
题目链接:http://codeforces.com/problemset/problem/589/D 题目大意:给出n个人行走的开始时刻,开始时间和结束时间,求每个人分别能跟多少人相遇打招呼(每两人 ...
- Codeforces 767B. The Queue 模拟题
B. The Queue time limit per test:1 second memory limit per test:256 megabytes input:standard input o ...
- codeforces #271D Good Substrings
原题链接:http://codeforces.com/problemset/problem/271/D 题目原文: D. Good Substrings time limit per test 2 s ...
- Codeforces 704A Thor 队列模拟
题目大意:托尔有一部手机可执行三种操作 1.x APP产生一个新消息 2.读取x App已产生的所有消息 3.读取前t个产生的消息 问每次操作后未读取的消息的数量 题目思路: 队列模拟,坑点在于竟然卡 ...
- Codeforces 316G3 Good Substrings 字符串 SAM
原文链接http://www.cnblogs.com/zhouzhendong/p/9010851.html 题目传送门 - Codeforces 316G3 题意 给定一个母串$s$,问母串$s$有 ...
- Vasya And The Mushrooms CodeForces - 1016C (前缀和模拟)
大意: 给定2*n的矩阵, 每个格子有权值, 走到一个格子的贡献为之前走的步数*权值, 每个格子只能走一次, 求走完所有格子最大贡献. 沙茶模拟打了一个小时总算打出来了 #include <io ...
随机推荐
- JQuery模仿淘宝天猫魔盒抢购页面倒计时效果
1.效果及功能说明 通过对时间的控制来告诉用户一个活动还剩多少时间,精确到秒.2.实现原理 首先定义活动的截至的时间,要重年份精确到毫秒,在获得当前的年份到秒钟,在用截至时间,减去现在的时间,剩下的还 ...
- Android -- 自定义标题栏,背景颜色填充满
设置标题栏背景 1> 准备背景图片: background_pix.png 注:用背景图片比用颜色好处,可以让背景看起来有凹凸感. 2> drawable文件夹下放xml文件 bitmap ...
- Android 如何修改默认输入法
前言 欢迎大家我分享和推荐好用的代码段~~ 声明 欢迎转载,但请保留文章原始出处: CSDN:http://www.csdn.net ...
- RUP---统一软件开发过程
更详细的见:http://www.ibm.com/developerworks/cn/rational/r-rupbp/ 本文引用:http://baike.baidu.com/view/223583 ...
- DFA 算法实现关键词匹配
起因: 从网页中爬去的页面.须要推断是否跟预设的关键词匹配(是否包括预设的关键词),并返回全部匹配到的关键词 . 眼下pypi 上两个实现 ahocorasick https://pypi.pytho ...
- 实现ssh的无password登录
这里所说的ssh是指OpenSSH SSHclient.是用于登录远程主机.而且在远程主机上运行命令.它的目的是替换rlogin和rsh,同一时候在不安全的网络之上,两个互不信任的主机之间,提供加密的 ...
- Oracle综合数据库管理命令集
sqlplus SANKYU/SANKYU@ORADB_192.168.25.235 cmd: exp .......(最后不要加;号)--sankyuexp SANKYU/SANKYU@SUNNY ...
- Hibernate常用查询语句
Hibernate常用查询语句 Hib的检索方式1'导航对象图检索方式.通过已经加载的对象,调用.iterator()方法可以得到order对象如果是首次执行此方法,Hib会从数据库加载关联的orde ...
- 使用Iperf工具测试android系统网络wifi的吞吐量wifithrougput
http://blog.csdn.net/bingxuebage/article/details/7534655 服务端:./iperf3 -s &客户端:./iperf3 -c 10.15. ...
- 微信小程序 - 自定义tabbar
更新: 2019-1-18:自定义tabbar组件已发布 各种奇葩的需求,造就了我们 wxml <view class="nav-tabs"> <view cla ...