https://www.acmicpc.net/problem/12904
12904번: A와 B
수빈이는 A와 B로만 이루어진 영어 단어가 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수
www.acmicpc.net
거꾸로 뒤집어서 생각하면 금방 풀리는 문제, 문제 설명도 괜찮고 난이도도 제법있습니다. 그리드가 어려운건지 골드라 어려운거지 .. ㅠ
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
string s,t;
cin >> s >> t;
int n=t.size();
int m = s.size();
int cnt = 0;
if (s == t) {
cout << 1;
return 0;
}
if (n < m) {
cout << 0;
return 0;
}
int indx = n-1;
while(true) {
if (t.size() == m) {
break;
}
if (cnt % 2 == 0) {
if (t[indx] == 'A') {
//a빼기
t.erase(t.end()-1);
}
else if (t[indx] == 'B') {
//b뺴고 문자열뒤집기
t.erase(t.end() - 1);
cnt++;
}
}
else {
if (t[0] == 'A') {
//a빼기
t.erase(t.begin());
}
else if (t[0] == 'B') {
//b뺴고 문자열뒤집기
t.erase(t.begin());
cnt++;
}
}
indx--;
}
if (cnt % 2 != 0) {
reverse(t.begin(), t.end());
}
if (s == t) {
cout << 1;
}
else {
cout << 0;
}
}
'알고리즘 공부' 카테고리의 다른 글
프로그래머스 게임맵최단거리(복습) (1) | 2023.10.19 |
---|---|
프로그래머스 다리를 지나는 트럭(복습) (1) | 2023.10.18 |
백준 ABCDE (복습) (0) | 2023.10.16 |
백준 색칠하기(복습) (0) | 2023.10.14 |
백준 숨바꼭질 3 (복습) (0) | 2023.10.12 |