#include<bits/stdc++.h>
using namespace std;
map<string,int>mp;
int main(void)
{
string s; cin>>s;
bool flag=0;
for(int i=0;i<s.size()+1;i++)
{
if(s[i]=='A'&&s[i+1]=='B')
{
if(mp.count("AB")==0) mp["AB"]=i;
if(mp.count("BA"))
{
int t=mp["BA"];
if(t+1!=i) flag=1;
}
}
if(s[i]=='B'&&s[i+1]=='A')
{
if(mp.count("BA")==0) mp["BA"]=i;
if(mp.count("AB"))
{
int t=mp["AB"];
if(t+1!=i) flag=1;
}
}
}
if(flag) puts("YES");
else puts("NO");
return 0;
}
A. Two Substrings【哈希表】
最新推荐文章于 2024-08-07 09:14:10 发布