CodeForces 550A Two Substrings(模拟)
来源:互联网 发布:轰炸手机号码软件 编辑:程序博客网 时间:2024/06/04 19:20
【题目链接】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;}
0 0
- CodeForces 550A Two Substrings(模拟)
- Codeforces-550A-Two Substrings
- 【codeforces 550A】Two Substrings
- CodeForces 550A Two Substrings 简单题
- CodeForces NO.550A Two Substrings(特AABAAB)
- Codeforces,306DIV.2A. Two Substrings
- coderforce 550A. Two Substrings
- Codeforces Round #306 (Div. 2)---A. Two Substrings
- Codeforces Round #306 (Div. 2) A. Two Substrings
- Codeforces Round #306 (Div. 2), problem: (A) Two Substrings
- A. Two Substrings
- codefotces #306 A 550A A. Two Substrings(枚举)
- Codeforces Round #306 (Div. 2) A. Two Substrings string两个函数使用
- CF#306- A - Two Substrings-水题
- Two Substrings
- Two Substrings
- Two Substrings
- Two Substrings
- 网页引用外部js脚本文件时必须是(转)
- 堆排序
- Go语言并发之美
- sort-list
- Checkpoint not complete造成oracle故障报告及解决方案
- CodeForces 550A Two Substrings(模拟)
- GitHub开源项目
- 内存卡加密王破解
- 【IOS】Instruments 使用教程
- 【Hadoop】5、Hadoop安装之cloudera manager(3)
- ubuntu 14.04 安装和卸载 cuda toolkit 7
- Linux 下编译并安装配置 Qt (完整版)
- 工作效率工具/常用方法
- JVM虚拟机结构