-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path12919_A와B_2.cpp
49 lines (40 loc) · 923 Bytes
/
12919_A와B_2.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
47
48
49
/*
12919 A와 B 2
골드5
Greedy
2022.10.11
*/
#include <bits/stdc++.h>
using namespace std;
string S, T;
void checkAB(string S, string T){
if(S == T) {
cout << '1' << endl;
exit(0);
}
if(S.length() >= T.length()) return;
string Tcopy;
if(T[T.length() - 1] == 'A'){
// 조건 1(뒤에 A만 한개 붙힘)으로 만든것임
// cout << '1' << ' ' << S << ' ' << T << endl;
Tcopy = T;
Tcopy.pop_back();
checkAB(S, Tcopy);
}
if(T[0] == 'B'){
// 조건 2(뒤에 B붙히고 reverse)으로 만든것임
// cout << '2' << ' ' << S << ' ' << T << endl;
Tcopy = T;
reverse(Tcopy.begin(), Tcopy.end());
Tcopy.pop_back();
checkAB(S, Tcopy);
}
}
int main(void) {
ios::sync_with_stdio(0);
cin.tie(0);
//initialize
cin >> S >> T;
checkAB(S, T);
cout << '0' << endl;
}