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 ...
随机推荐
- 国庆大礼包:2014年最全的ANDROID GUI模板和线框图免费下载
距离上次分享GUI模板有很长时间了,这段时间里设计趋势不断变化,谷歌推出了最新的Android L以及全新的界面设计,UI设计师又有得忙了,今天收集了一组实用的GUI模板和线框图,包含最新的Andro ...
- a标签默认颜色
<a href="www.baidu.com">test</a> <span style="color:#428bca;"> ...
- Systemd 三部曲 之 PHP7
安装编译php7时需要的依赖包 : yum -y install libxml2 libxml2-devel openssl openssl-devel curl-devel libjpeg-deve ...
- Discuz 学习笔记一 :getgdc 和get_client_ip
Getgdc函数 discuz有一个超级变量的自定义函数: function getgpc($k, $type='GP') { $type = strtoupper($type); ...
- 知识共享图文直播---(一)将数据库中的数据加载到MSFlexGrid空间中再导入Excel
熟话说万物皆有其存在的道理,为什么我突然想写<知识共享图文直播>这个系列呢?首先,我想的是记录自己学习的历程,在记录中加深自己对知识的理解,同时也希望自己的博文能帮助到其他数据库的初学者. ...
- PHP高级教程-Cookie
PHP Cookie cookie 常用于识别用户. Cookie 是什么? cookie 常用于识别用户.cookie 是一种服务器留在用户计算机上的小文件.每当同一台计算机通过浏览器请求页面时,这 ...
- C# Console 运行之后最小化到状态栏
static void Main(string[] args) { new ConsoleCtrl(); Console.Read(); } class ConsoleCtrl { [DllImpor ...
- Showing a tooltip
We can provide a balloon help for any of our widgets. #!/usr/bin/python # -*- coding: utf-8 -*- &quo ...
- atitit.提升开发效率---MDA 软件开发方式的革命(3)----自己主动化建表
atitit.提升开发效率---MDA 软件开发方式的革命(3)----自己主动化建表 1. 建模在后自己主动建表 1 1. 传统上,须要首先建表,在业务编码.. 1 2. 模型驱动建表---很多其它 ...
- 通过jdbc使用PreparedStatement,提升性能,防止sql注入
为什么要使用PreparedStatement? 一.通过PreparedStatement提升性能 Statement主要用于执行静态SQL语句,即内容固定不变的SQL语句.Statement每执行 ...