Codeforces Round #306 (Div. 2) A. Two Substrings 水题
A. Two Substrings
Time Limit: 20 Sec
Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/550/problem/A
Description
Input
Output
Print "YES" (without the quotes), if string s contains two non-overlapping substrings "AB" and "BA", and "NO" otherwise.
Sample Input
ABA
Sample Output
NO
HINT
题意
判断字符串是否存在不重合的AB和BA
题解:
虽然是一道傻逼题,但是被cha的人很多
我提供两组数据ABACCAB 和ABAB
这两组数据,来感受一下~
代码:
- //qscqesze
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- #include <ctime>
- #include <iostream>
- #include <algorithm>
- #include <set>
- #include <vector>
- #include <sstream>
- #include <queue>
- #include <typeinfo>
- #include <fstream>
- #include <map>
- #include <stack>
- typedef long long ll;
- using namespace std;
- //freopen("D.in","r",stdin);
- //freopen("D.out","w",stdout);
- #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
- #define test freopen("test.txt","r",stdin)
- #define maxn 2000001
- #define mod 10007
- #define eps 1e-9
- int Num;
- char CH[];
- const int inf=0x3f3f3f3f;
- const ll infll = 0x3f3f3f3f3f3f3f3fLL;
- inline ll read()
- {
- ll x=,f=;char ch=getchar();
- while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
- while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
- return x*f;
- }
- inline void P(int x)
- {
- Num=;if(!x){putchar('');puts("");return;}
- while(x>)CH[++Num]=x%,x/=;
- while(Num)putchar(CH[Num--]+);
- puts("");
- }
- //**************************************************************************************
- int main()
- {
- //test;
- string s;
- string s1;
- cin>>s;
- s1=s;
- int flag=;
- int n=s.size();
- for(int i=;i<n-;i++)
- {
- if(s1[i]=='B'&&s1[i+]=='A')
- {
- flag=,s1[i]='#',s1[i+]='#';
- break;
- }
- }
- if(flag==)
- {
- for(int i=;i<n-;i++)
- {
- if(s1[i]=='A'&&s1[i+]=='B')
- {
- cout<<"YES"<<endl;
- return ;
- }
- }
- }
- s1=s;
- flag=;
- for(int i=;i<n-;i++)
- {
- if(s1[i]=='A'&&s1[i+]=='B')
- {
- flag=,s1[i]='#',s1[i+]='#';
- break;
- }
- }
- if(flag==)
- {
- for(int i=;i<n-;i++)
- {
- if(s1[i]=='B'&&s1[i+]=='A')
- {
- cout<<"YES"<<endl;
- return ;
- }
- }
- }
- cout<<"NO"<<endl;
- return ;
- }
Codeforces Round #306 (Div. 2) A. Two Substrings 水题的更多相关文章
- 水题 Codeforces Round #306 (Div. 2) A. Two Substrings
题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...
- Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)
Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...
- Codeforces Round #334 (Div. 2) A. Uncowed Forces 水题
A. Uncowed Forces Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/604/pro ...
- Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题
A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...
- Codeforces Round #306 (Div. 2) 550A Two Substrings
链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...
- Codeforces Round #306 (Div. 2) A. Two Substrings【字符串/判断所给的字符串中是否包含不重叠的“BA” “AB”两个字符串】
A. Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard i ...
- Codeforces Round #327 (Div. 2) A. Wizards' Duel 水题
A. Wizards' Duel Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/591/prob ...
- Codeforces Round #146 (Div. 1) A. LCM Challenge 水题
A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...
- Codeforces Round #335 (Div. 2) B. Testing Robots 水题
B. Testing Robots Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://www.codeforces.com/contest/606 ...
随机推荐
- linux 常用端口列表
常见端口表汇总 1 tcpmux TCP Port Service Multiplexer 传输控制协议端口服务多路开关选择器 2 compressnet Management Utility com ...
- VMware 命令行下安装以及导入Ubuntu系统
前提: 鉴于个人PC性能太弱,考虑是否可以将在PC上搭建好的环境移植到高性能服务器上.想到后就干呗. 下载完对应操作系统的安装包后按如下步骤操作: 安装包名称:VMware-Workstation-F ...
- (转载)OC学习篇之---类的延展
前一篇文章我们介绍了类的类目概念和使用,那么这篇文章我们继续来介绍一下OC中的一个特性:延展. 其实说白了,延展就是弥补C语言中的前向申明,我们知道,在C语言中,如果你想调用一个函数的话,那么在此之前 ...
- Window.onLoad 和 DOMContentLoaded事件的先后顺序
相信写js的,都知道window.onload吧,但是并不是每个人都知道DOMContentLoaded,其实即使你不知道,很有可能你也经常使用了这个东西. 一般情况下,DOMContentLoade ...
- Kali vmtools
参考链接:http://www.leavesongs.com/SHARE/kali-vmtools-install.html 安装环境:kali-1.1.0 ---3.18.0-kali1-amd ...
- 分布式文件系统--GFS
分布式文件系统 分布式文件系统:当数据集的大小超过一台独立物理计算机的存储能力时,就有必要对它进行分区(partition)并存储到若干台单独的计算机上.管理网络中夸多台计算机存储的文件系统.这种系统 ...
- Java基础 —— JavaScript
Javascript:基于对象与事件驱动的脚本语言,主要用于客户端 特点: 交互性:信息动态交互. 安全性:不能访问本地硬盘. 跨平台性:只要有浏览器就支持Javascript,与平台无关. Java ...
- JavaScript的function对象
我必须先说Java与JavaScript没有关系,不是我以前想的那个样子的(JavaScript是Java的一种超进化) 在JavaScript中,函数(function)就是对象. JavaScri ...
- 支付结果回调v7核心,投保确认接口..
<?xml version="1.0" encoding="GBK"?> <PACKET type="REQUEST"&g ...
- hdu 1260 Tickets
http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...