12904번: A와 B

풀이

직접 시뮬레이션 해보면 된다!

코드

#include <bits/stdc++.h>
using namespace std;

string S, T;

void reverse(string K) {
	for (int i = 0; i < K.length(); ++i)
		T[K.length() - i - 1] = K[i];
}

int main() {
	cin >> S >> T;
	
	int flag = 0;
	while (true) {
		if (S.length() == T.length()) {
			if (!S.compare(T)) flag = 1;
			break;
		}
		int len = T.length() - 1;
		char now = T[len];
		T.erase(len);
		if (now == 'B')
			reverse(T);
	}
	printf("%d", flag);

	return 0;
}
wookje.kwon's profile image

wookje.kwon

2017-03-06 15:20

Read more posts by this author