Just think these case:
ABA with (AB or BA)
BAB with (AB or BA)
AB and BA
///Bismillahir Rahmanir Rahim
///Author: Tanvir Ahmmad
///CSE,Islamic University,Bangladesh
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
#include<sstream>
#include<cmath>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<vector>
#include<iterator>
#include <functional> ///sort(arr,arr+n,greater<int>()) for decrement of array
/*every external angle sum=360 degree
angle find using polygon hand(n) ((n-2)*180)/n*/
///Floor[Log(b) N] + 1 = the number of digits when any number is represented in base b
using namespace std;
typedef long long ll;
int main()
{
bool check1=false,check2=false,check3=false;
string str,proof="Z";
cin>>str;
string again=str;
for(ll i=0; i<str.size()-1; i++)
{
if(str[i]=='A' && str[i+1]=='B' && str[i+2]=='A' && check1==false) str[i]=str[i+1]=str[i+2]=proof[0],check1=true,i+=2;
else if(str[i]=='B' && str[i+1]=='A' && str[i+2]=='B' && check1==false) str[i]=str[i+1]=str[i+2]=proof[0],check1=true,i+=2;
else if(str[i]=='A' && str[i+1]=='B' && check2==false) str[i]=str[i+1]=proof[0],check2=true,i++;
else if(str[i]=='B' && str[i+1]=='A' && check3==false) str[i]=str[i+1]=proof[0],check3=true,i++;
}
if((check1 && (check2 || check3)) || (check2 && check3)) cout<<"YES"<<endl;
else cout<<"NO"<<endl;
return 0;
}
///Alhamdulillah
Problem link:https://codeforces.com/contest/550/problem/A
Comments
Post a Comment