"Topic link" click here~~
"To the effect of the topic":
You are given string s. Your task is to determine if the given string s contains the non-overlapping substrings "AB" and "BA" (The substrings can Go in any order).
Input
The only line of input contains a string s of length between 1 and consisting of uppercase Latin letters.
Output
Print "YES" (without the quotes), if string s contains the non-overlapping substrings "AB" and "BA", and "NO" otherwise.
Sample Test (s)
Input
ABA
Output
NO
Input
Bacfab
Output
YES
Gives a line of characters to determine if there are two non-overlapping strings "AB" and "BA"
Code:
The /*str.find () function returns the position of the first occurrence of STR in the string, starting with index. Returns String::npos if not found, returns the position where Str first appears in the string (from index, length). Returns String::npos if not found, returns the position of the first occurrence of the character ch in the string (from index). If not found, return to String::npos * *#include <bits/stdc++.h>using namespace STD;stringStrintMain () {Cin>>str;intLen=str.size ();if(len<=3)puts("NO");Else{intA=str.find ("AB");intB=str.find ("BA", A +2);intC=str.find ("BA");intD=str.find ("AB", c+2);if(a!=-1&&b!=-1|| c!=-1&&d!=-1)puts("YES");Else puts("NO"); }return 0;}/*strstr function: Find where the string first appears */#include <bits/stdc++.h>using namespace STD;Charstr[200000],*p;intMain () {Cin>>str;if((p=strstr(STR,"AB")) && (strstr*pi2,"BA")))puts("YES");Else if((p=strstr(STR,"BA")) &&strstr*pi2,"AB"))puts("YES");Else puts("NO");return 0;}
Codeforces 550A substrings (analog)