Two Substrings

L2tp环境搭建笔记- Openwrt平台 本文使用3台openwrt设备, 分别搭建L2TP服务和2个客户端, 进行端到端验证和局域网组网,并分析搭建过程中涉及的默认路由( defaultroute) 配置问题。 阅读详情

 Two Substrings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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
input
AXBYBXA
output
NO
Note

In the first sample test, despite the fact that there are substrings "AB" and "BA", their occurrences overlap, so the answer is "NO".

In the second sample test there are the following occurrences of the substrings: BACFAB.

In the third sample test there is no substring "AB" nor substring "BA".

给一个字符串,找AB和BA,但是AB和BA不能重合,比如ABA不算。直接就是模拟,分类,先找AB,再找BA,然后还有一个先找BA,再找AB。再定义一个标兵,最后输出。

#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
char c[100005];
int main()
{
 int i, j, m, n, leap;
 scanf("%s", c);
 int len = strlen(c); leap = 0; int leap1 = 0;
 for (i = 0; i < len - 1; i++)
 {
  if (c[i] == 'A'&&c[i + 1] == 'B'&&!leap)
  {
   leap = 1;
   i++;
  }
  else if (leap == 1 && !leap1&&c[i] == 'B'&&c[i + 1] == 'A')
   leap1 = 1;
  if (leap1 == 1)break;
 }
 if (leap1 == 1)
  cout << "YES" << endl;
 else
 {
  leap = leap1 = 0;
  for (i = 0; i < len - 1; i++)
  {
   if (c[i] == 'B'&&c[i + 1] == 'A'&&!leap)
   {
    leap = 1;
    i++;
   }
   else if (leap == 1 && !leap1&&c[i] == 'A'&&c[i + 1] == 'B')
    leap1 = 1;
   if (leap1 == 1)break;
  }
  if (leap1 == 1)
   cout << "YES" << endl;
  else
   cout << "NO" << endl;
 }
 return 0;
}

lammps 案例in文件汇总 进阶案例: 聚乙烯和石墨烯界面pull out模拟代码 反应力场reax/c设置方法及案例解析 石墨烯热导率模拟代码(NEMD方法) 圆锥形SiC纳米磨削单晶硅源代码 高熵合金FeNiCrCoCu纳米压痕模拟代码 fix indent命令实现纳米摩擦及摩擦力计算 Fe原子辐照轰击多层石墨烯模拟代码 铝基石墨烯复合物压缩变形in文件源代码 石墨烯自动卷曲到Fe纳米线模拟源代码 铝/石墨烯复合物结晶过程lammps模 阅读详情

相关推荐

Windows环境Oracle19C安装与配置全攻略

本文详细介绍了在Windows环境下安装与配置Oracle19C数据库的完整流程,包括环境准备、安装步骤、网络配置、客户端工具设置及常见问题解决方案。特别针对Windows 10和Windows Server 2016及以上版本提供了优化建议,帮助用户高效完成Oracle19C的部署与维护。

weixin_28455801的博客 487

Two Substrings (在字符串中查找某一段字符:strstr函数)

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 inp

Markfound's blog 480

闲人闲谈PS之一项目库存跨公司业务STO解决方案--SAP闲人的开篇

写这篇文章之前,简单说一下发这篇文章的动机。也算是在SAP这一行干了快10多年,在对一个模块了解越来越深入,越发觉自己的SAP知识浅薄。总的来说,和多数顾问一样,对于**标准功能**的应用业务场景理解还是存在或多或少的知识盲区。 因为一个偶然,看到SAP团子君的文章,分享了很多干货文章。这也是自己一直想做的时候,不管水平高低与否,分享本身就意味着提升。好了废话不多说,先在优快云上发一篇吧,困惑自己将近10年的问题的解决方案。 业务场景:在项目型企业中,通常会有这样的业务,母公司和客...

SAP闲人的博客 9266

Codeforces 550 A. Two Substrings

A. Two Substringstime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputYou are given string s. Your task is to determine if the given string s contains ...

howell 300

VASPKIT绘制平面平均电荷差分密度

平面平均密度差(planar-averaged electron density difference)是密度差的衍生。密度差是个三维空间函数,经常通过绘制平面图、等值面图方式图形化考察。虽然这两种图很直观,但平面图会受到截面选取的影响,而等值面图会受到等值面数值(isovalue)选取的影响,因此都有一定任意性,也不容易定量讨论。对于电子转移有比较明确方向的情况,可以绘制平面平均密度差曲线,由此可以清楚地考察垂直于选取的方向上每个截面上的密度差积分值,在定量讨论、对比上比较便利。

weixin_43948934的博客 1万+

从入门到精通:dirmap 高级 Web 目录扫描实战指南

本文提供了一份从环境搭建到高级配置的dirmap Web目录扫描实战指南。详细解析了工具安装、核心配置文件dirmap.conf的深度调优,包括递归扫描、四种扫描模式(字典、爆破、爬虫、Fuzz)的实战应用,并演示了分阶段资产发现的完整工作流程,帮助安全人员高效发现隐藏目录与敏感文件。

rnn9storyteller的博客 479

A. Two Substrings

time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given string s. Your task is to determine if the given s

无知的我 1560

Ubuntu单系统安装全攻略:从删除Windows到UEFI引导设置(避坑指南)

本文提供Ubuntu单系统安装的完整指南,涵盖从安全删除Windows系统到UEFI引导设置的详细步骤。通过专业工具准备、分区方案设计、引导加载器配置等关键环节,帮助用户避免常见安装问题,实现纯净高效的Ubuntu单系统环境。特别强调UEFI引导的深度配置与安装后的性能优化,适合希望彻底转向Linux的用户。

weixin_29210727的博客 409

550A Two Substrings

Codeforces刷题

算法竞赛入门,越专注,越成功。 141

PADS VX2.4差分对设置避坑指南:常见错误与解决方案

本文深度解析了在PADS VX2.4中进行高速PCB设计时,差分对设置的核心要点与常见陷阱。针对Layout规则设置、Router布线实战中的阻抗控制、线长匹配等关键环节,提供了具体的避坑指南和解决方案,帮助工程师确保信号完整性,提升设计质量。

weixin_29216049的博客 359

【AUTOSAR-DEM】-2.4-APP SWC如何读取MIL灯状态以及配置MIL灯

该篇博文将告诉您: MIL(Malfunction Indicator Lamp/Light)灯的点灯和灭灯过程; DEM模块如何配置MIL灯; APP SWC如何获取MIL灯状态。

「汽车电子助手」的博客 1710

Codeforces 550A Two Substrings

目录题目输入输出样例输入1输出1输入2输出2输入3输出3提示题意思路(罚自己写一题多解)一、代码二、代码(Runtime error on test 19) 题目 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). 输入 The onl

夏午Sharve的博客? 885

Linux 4.19、Linux 5.10、Linux 6.1 三个版本详细分析

Linux 4.19发布日期:2018年10月22日LTS 状态:是长期支持版本,官方支持到2024年12月。Linux 5.10发布日期:2020年12月13日LTS 状态:LTS 版本,官方支持到2026年12月。Linux 6.1发布日期:2022年12月11日LTS 状态:不是官方的LTS版本,但通常社区会为新的版本提供一定时间的支持。定位:稳定性和长期支持,广泛应用于多种平台,尤其是嵌入式系统和服务器。主要优势:稳定性高,广泛的硬件支持,核心功能可靠。

小灰灰的博客 5950

【codeforces 550A】Two Substrings

time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output You are given string s. Your task is to determine if the given string s cont...

223

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

CF Two Substrings

Two Substrings time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given strings. Your task is to determine if...

weixin_34303897的博客 118

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

A - Two Substrings

Time Limit:2000MSMemory Limit:262144KB64bit IO Format:%I64d & %I64u Description You are given strings. Your task is to determine if the given stringscontains two non-overla...

weixin_30784141的博客 110

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

550A - Two Substrings

链接: https://codeforces.com/problemset/problem/550/A 题意: 水题,字符串里找没有重合的AB和BA 解: 暴力搜两次 实际代码: #include<iostream> #include<algorithm> #include<cmath> #include<algorithm> using namespace std; typedef long long int ll; int main() { string

Fei_WuYan的博客 269
下一篇: Preparing Olympiad
Techay
博客等级 码龄11年 11粉丝 174原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值