链接:
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 a;
cin>>a;
int lg=a.length();
bool ans=0;
bool book=0;
for(int i=0;i<lg-1;i++)
{
if(a[i]=='A' && a[i+1]=='B' && book==0)
{
book=1;
i++;
}
else if(a[i]=='B' && a[i+1]=='A' && book==1)
{
ans=1;
break;
}
}
if(!ans)
{
book=0;
for(int i=0;i<lg-1;i++)
{
if(a[i]=='B' && a[i+1]=='A' && book==0)
{
book=1;
i++;
}
else if(a[i]=='A' && a[i+1]=='B' && book==1)
{
ans=1;
break;
}
}
}
if(ans) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
}
限制:
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output