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 ...
随机推荐
- IE9对HTML5中一部分属性不提供支持的原因
为什么在IE9中对于HTML5标准中的离线应用程序以及CSS3中的一部分不提供支持?笔者间接了解到了这个原因. 微软日前已经发布了Internet Explorer 9(以下简称IE9)正式版.在该版 ...
- 《iOS Human Interface Guidelines》——Search Bar
搜索栏 搜索栏接收用户输入用于搜索的文本(例如以下,带有占位文本). API NOTE 查看UISearchBar学习怎样在你的代码中定义搜索栏.查看UISearchDisplayController ...
- CAD批量合并文件
要求:将整饰完成504幅单独的宗地图合并成一张总图,合并后,去掉其他要素,只保留毕合的权属线. 解决: 1.合并dwg文件,除了手工粘贴复制外,最先想到的是插入块,即用Insert命令插入,测试结果可 ...
- android 如何连真机测试
1. 设置android手机为USB调试模式.步骤: menu---> 设置 ---> 应用程序 ---> 开发 , 选择[USB调试] 2. 用USB连接手机和电脑,并确保成功.步 ...
- SqlServer日常积累(二)
1.Like运算符:将字符串表达式与 SQL表达式中的模式进行比较匹配. 语法 :expression Like 'pattern' ,expression为匹配字段,pattern为匹配字符串.可以 ...
- libcurl 接口调用方式
http://hi.baidu.com/tracyu1026/item/bb6d5def4292b10b570f1d48 libcurl提供了一组C语言API函数直接调用.首先需要提到的两个函数就是c ...
- 11g relocate scan ip
今天安装了Oracle 11.2.0.4的数据库,由于在安装GRID软件是,跑脚本的时候是现在节点2上跑的,跑完之后然后在节点1上跑.发现我的scan_ip在节点2上,我想把scan_ip reloc ...
- 把mysql数据库生成数据字典,直接可用
便于查看数据库表.字段,做一个数据字典是很有必要的,下面只需要简单更改下配置就可以用了,样式也是挺好的. <?php header('content-type:text/html;charset ...
- cmd命令怎么玩
1.两种进入cmd窗口方式: 1)win+R,出现运行窗口,输入cmd按回车 2)点击开始旁边的搜索文件和程序框按钮(Cortana),输入cmd按回车 2.常用命令 执行运行 comp ...
- Android:Dialog中隐藏键盘的注意事项
场景:弹出一个Dialog.里面有一个EditText.用来输入内容.由于输入时.须要弹出键盘.所以当Dialog消失时.键盘要一起隐藏. 如今我们做一个自己定义的Dialog MyDialog ex ...