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;
}