[백준/BOJ] 12904. A와 B [Gold 5]

jychan99·2022년 1월 3일
0
post-thumbnail
  1. A와 B

문제출처 : https://www.acmicpc.net/problem/12904

code

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

int main()
{
	ios::sync_with_stdio(false);

	string S, T;
	
	cin >> S;
	cin >> T;
	int S_len = S.length(), T_len = T.length();

	while (T_len > S_len)
	{
		if (T[T_len - 1] == 'A')
		{
			T.pop_back();
			T_len--;
		}
		else
		{
			T.pop_back();
			T_len--;
			reverse(T.begin(), T.end());
		}
	}

	S==T ? cout << 1 : cout << 0;

	return 0;
}

S에서 T를 맞추려고 하는거보다 T에서 S로 거꾸로 빼면서 맞추려고 하다보면 풀기가 더욱 수월해질수 있다.

하면서 string.pop_back()이라는 함수를 새로 배웠다.
그리고 C++에서는 문자열비교할때 그냥 ==으로 된다는사실도 깨달았다.

profile
내가 지금 두려워 하고 있는 일이 바로 내가 지금 해야 할 일이다. 🐥

0개의 댓글