-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path550A.cpp
More file actions
60 lines (58 loc) · 1.28 KB
/
Copy path550A.cpp
File metadata and controls
60 lines (58 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,n) for(int i = 0;i<n;i++)
void solve() {
int ab = 0, ba = 0;
bool aba = false, bab = false;
string s; cin >> s;
int n = s.size();
REP(i, n){
if(s[i] == 'A'){
if(i < n-1){
if(s[i+1] == 'B'){
ab++; i++;
if(s[i+1] == 'A'){
aba = true;
i++;
}
}
}
}
else if(s[i] == 'B'){
if(i < n-1){
if(s[i+1] == 'A'){
ba++; i++;
if(s[i+1] == 'B'){
bab = true;
i++;
}
}
}
}
}
// cout << ab << " " << ba << " " << aba << " " << bab << endl;
if(!ba){
if(aba){
ba++; ab--;
}
}
if(!ab){
if(bab){
ab++; ba--;
}
}
// cout << ab << " " << ba << endl;
if(ab >= 1 && ba >= 1) cout << "YES\n";
else cout << "NO\n";
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int test = 1;
// cin >> test;
while(test--){
solve();
}
return 0;
}