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 ...
随机推荐
- Facade 门面模式 封装 MD
门面模式 简介 作用:封装系统功能,简化系统调用 门面模式要求一个系统的外部与其内部的通信必须通过一个统一的门面(Facade)对象进行.门面模式提供一个高层次的接口,使得系统更易于使用. 门面模式的 ...
- 记录C#错误日志工具
在编程过程中,我们经常会用try...catch处理可能出错的代码块.如果程序出现错误,则直接show出错误信息. 当然,大型的系统都有错误日志处理模块,用数据库记录错误日志信息,有相应的写入错误日志 ...
- select2插件替换掉数据列表为空时候的No results found的提示
$(".select2").select2({ language: { noResults: function (params) { return "暂无数据" ...
- [Javascirpt] Immediately-Invoked function!!! IMPORTANT
var parkRides = [["Birch Bumpers", 40], ["Pines Plunge", 55], ["Cedar Coast ...
- 30款免费的手机UI设计资源
在 原型设计阶段,我们会尽量寻找一些灵感刺激大脑,从而让我们的想象力飞-灵感给了我们很好的开始,但是当我们把灵感化为现实的时候,又需要一些实用而又高 效的组件来完成.即使你有非常善于把灵感实例化在草稿 ...
- 【iOS】网络操作与AFNetworking
众所周知.苹果搞的一套框架NSContention发送请求与接收请求的方式十分繁琐.操作起来非常不方便. 不仅要做区分各种请求设置各种不同的參数,并且还要常常在多线程里操作,同一时候还要对请求与返回的 ...
- Discuz常见大问题-如何使用云采集插件
在百度中搜discuz 云采集插件(直接在Discuz官方的插件库中搜可能搜不到) 启用这个插件 随后在任意版块发帖的时候,顶部都会有一个文本框,可以直接放别人博客的帖子,点击获取将生成到你发的帖子中 ...
- qtp:vbs基础教程
◎Vbs脚本编程简明教程之中的一个-为什么要使用Vbs? 在Windows中,学习计算机操作或许非常easy,可是非常多计算机工作是反复性劳动,比如你每周或许须要对一些计算机文件进行复制.粘贴.改名 ...
- Android自动填写获取到的验证码
Android需要添加的相关权限 <uses-permission android:name="android.permission.RECEIVE_SMS">< ...
- Linux网卡高级命令
网卡的高级命令 [root@gechong ~]# mii-tool No interface specified usage: mii-tool [-VvRrwl] [-A media,... | ...