A. Two Substrings

Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/550/problem/A

Description

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 Input

ABA

Sample Output

NO

HINT

题意

判断字符串是否存在不重合的AB和BA

题解:

虽然是一道傻逼题,但是被cha的人很多

我提供两组数据ABACCAB 和ABAB

这两组数据,来感受一下~

代码:

  1. //qscqesze
  2. #include <cstdio>
  3. #include <cmath>
  4. #include <cstring>
  5. #include <ctime>
  6. #include <iostream>
  7. #include <algorithm>
  8. #include <set>
  9. #include <vector>
  10. #include <sstream>
  11. #include <queue>
  12. #include <typeinfo>
  13. #include <fstream>
  14. #include <map>
  15. #include <stack>
  16. typedef long long ll;
  17. using namespace std;
  18. //freopen("D.in","r",stdin);
  19. //freopen("D.out","w",stdout);
  20. #define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
  21. #define test freopen("test.txt","r",stdin)
  22. #define maxn 2000001
  23. #define mod 10007
  24. #define eps 1e-9
  25. int Num;
  26. char CH[];
  27. const int inf=0x3f3f3f3f;
  28. const ll infll = 0x3f3f3f3f3f3f3f3fLL;
  29. inline ll read()
  30. {
  31. ll x=,f=;char ch=getchar();
  32. while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
  33. while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
  34. return x*f;
  35. }
  36. inline void P(int x)
  37. {
  38. Num=;if(!x){putchar('');puts("");return;}
  39. while(x>)CH[++Num]=x%,x/=;
  40. while(Num)putchar(CH[Num--]+);
  41. puts("");
  42. }
  43. //**************************************************************************************
  44.  
  45. int main()
  46. {
  47. //test;
  48. string s;
  49. string s1;
  50. cin>>s;
  51. s1=s;
  52. int flag=;
  53. int n=s.size();
  54. for(int i=;i<n-;i++)
  55. {
  56. if(s1[i]=='B'&&s1[i+]=='A')
  57. {
  58. flag=,s1[i]='#',s1[i+]='#';
  59. break;
  60. }
  61. }
  62. if(flag==)
  63. {
  64. for(int i=;i<n-;i++)
  65. {
  66. if(s1[i]=='A'&&s1[i+]=='B')
  67. {
  68. cout<<"YES"<<endl;
  69. return ;
  70. }
  71. }
  72. }
  73. s1=s;
  74. flag=;
  75. for(int i=;i<n-;i++)
  76. {
  77. if(s1[i]=='A'&&s1[i+]=='B')
  78. {
  79. flag=,s1[i]='#',s1[i+]='#';
  80. break;
  81. }
  82. }
  83. if(flag==)
  84. {
  85. for(int i=;i<n-;i++)
  86. {
  87. if(s1[i]=='B'&&s1[i+]=='A')
  88. {
  89. cout<<"YES"<<endl;
  90. return ;
  91. }
  92. }
  93. }
  94. cout<<"NO"<<endl;
  95. return ;
  96. }

Codeforces Round #306 (Div. 2) A. Two Substrings 水题的更多相关文章

  1. 水题 Codeforces Round #306 (Div. 2) A. Two Substrings

    题目传送门 /* 水题:遍历一边先找AB,再BA,再遍历一边先找BA,再AB,两种情况满足一种就YES */ #include <cstdio> #include <iostream ...

  2. Codeforces Round #367 (Div. 2) A. Beru-taxi (水题)

    Beru-taxi 题目链接: http://codeforces.com/contest/706/problem/A Description Vasiliy lives at point (a, b ...

  3. 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 ...

  4. Codeforces Round #353 (Div. 2) A. Infinite Sequence 水题

    A. Infinite Sequence 题目连接: http://www.codeforces.com/contest/675/problem/A Description Vasya likes e ...

  5. Codeforces Round #306 (Div. 2) 550A Two Substrings

    链接:http://codeforces.com/contest/550/problem/A 这是我第一次玩cf这种比赛,前面做了几场练习,觉得div2的前面几个还是比较水的. 所以看到这道题我果断觉 ...

  6. 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 ...

  7. 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 ...

  8. Codeforces Round #146 (Div. 1) A. LCM Challenge 水题

    A. LCM Challenge 题目连接: http://www.codeforces.com/contest/235/problem/A Description Some days ago, I ...

  9. 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 ...

随机推荐

  1. linux 常用端口列表

    常见端口表汇总 1 tcpmux TCP Port Service Multiplexer 传输控制协议端口服务多路开关选择器 2 compressnet Management Utility com ...

  2. VMware 命令行下安装以及导入Ubuntu系统

    前提: 鉴于个人PC性能太弱,考虑是否可以将在PC上搭建好的环境移植到高性能服务器上.想到后就干呗. 下载完对应操作系统的安装包后按如下步骤操作: 安装包名称:VMware-Workstation-F ...

  3. (转载)OC学习篇之---类的延展

    前一篇文章我们介绍了类的类目概念和使用,那么这篇文章我们继续来介绍一下OC中的一个特性:延展. 其实说白了,延展就是弥补C语言中的前向申明,我们知道,在C语言中,如果你想调用一个函数的话,那么在此之前 ...

  4. Window.onLoad 和 DOMContentLoaded事件的先后顺序

    相信写js的,都知道window.onload吧,但是并不是每个人都知道DOMContentLoaded,其实即使你不知道,很有可能你也经常使用了这个东西. 一般情况下,DOMContentLoade ...

  5. Kali vmtools

    参考链接:http://www.leavesongs.com/SHARE/kali-vmtools-install.html   安装环境:kali-1.1.0 ---3.18.0-kali1-amd ...

  6. 分布式文件系统--GFS

    分布式文件系统 分布式文件系统:当数据集的大小超过一台独立物理计算机的存储能力时,就有必要对它进行分区(partition)并存储到若干台单独的计算机上.管理网络中夸多台计算机存储的文件系统.这种系统 ...

  7. Java基础 —— JavaScript

    Javascript:基于对象与事件驱动的脚本语言,主要用于客户端 特点: 交互性:信息动态交互. 安全性:不能访问本地硬盘. 跨平台性:只要有浏览器就支持Javascript,与平台无关. Java ...

  8. JavaScript的function对象

    我必须先说Java与JavaScript没有关系,不是我以前想的那个样子的(JavaScript是Java的一种超进化) 在JavaScript中,函数(function)就是对象. JavaScri ...

  9. 支付结果回调v7核心,投保确认接口..

    <?xml version="1.0" encoding="GBK"?> <PACKET type="REQUEST"&g ...

  10. hdu 1260 Tickets

    http://acm.hdu.edu.cn/showproblem.php?pid=1260 题目大意:n个人买票,每个人买票都花费时间,相邻的两个人可以一起买票以节约时间: 所以一个人可以自己买票也 ...