-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy path191.cpp
46 lines (43 loc) · 843 Bytes
/
191.cpp
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
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <fstream>
#include <algorithm>
#include <string>
#define rep(i,j,k) for (int i=j;i<=k;++i)
#define rrep(i,j,k) for (int i=j;i>=k;--i)
using namespace std;
char stack[33333];
string str;
int top;
int main()
{
ios::sync_with_stdio(false);
cin >> stack[top = 1];
cin >> str;
bool check = true;
rep(i,0,str.size()-1)
{
if (top == 0) {check = false;break;}
if (str[i]=='A')
{
if (stack[top] == 'A')
stack[++top] = 'B';
else
top--;
}
else
{
if (stack[top] == 'B')
stack[++top] = 'A';
else
top--;
}
}
if (top!=0) check = false;
if (check) cout << "YES" << endl;
else cout << "NO" << endl;
return 0;
}