# A.Two Substrings

A.Two Substrings

A.两个子字符串

time limit per test:2 seconds
每次测试的时间限制:2秒

memory limit per test: 256 megabytes
每次测试的内存限制:256兆字节

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
您将得到字符串。您的任务是确定给定字符串s是否包含两个不重叠的子字符串。

“AB” and “EA” (the substrings can go in any order).
“AB”和“EA”(子子可以按任何顺序排列)。

lnput
输入

The only line of input contains a string s of length between 1 and 103consisting of uppercase Latin letters.
唯一的输入行包含长度介于1到103之间的字符串,由大写拉丁字母组成。

output
输出量

Print"“Es”(without the quotes), if string s contains two non-overlapping substrings “AE” and “BA”, and “o”
打印“es”(没有引号),如果字符串s包含两个不重叠的子字符串“AE”和“ba”,以及“o”。

otherwise.
不然的话。
状态自动机

char a[100001] = {0};
int main() 
{
	int x=0,y=0,z=0,k=0,e=1;//ba,bab,ab,aba
	while (a[e-1] != '\n')
	{
		a[e]=getchar();
		++e;
	}
	for (int i = 0; i < e; ++i)
	{
		if ('A' == a[i])
		{
			if (i && 'B' == a[i - 1])
			{
				if (i < e - 1 && 'B' == a[i + 1])
				{
					if (i > 1 && 'A' == a[i - 2])
						++k;
					else
						++y;
				}
				else
					++x;
			}
			else if (i < e - 1 && 'B' == a[i + 1])
			{
			if(!i<e-1'A'==[i+1])
			++z
			}
				
		}
	}
	if ((x+y+z+k>1)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值