자기개발👨‍💻/코딩 알고리즘

[C++] 백준 12919 A와 B 2

천숭이 2020. 8. 8. 22:28

https://www.acmicpc.net/problem/12919

 

12919번: A와 B 2

수빈이는 A와 B로만 이루어진 영어 단어 존재한다는 사실에 놀랐다. 대표적인 예로 AB (Abdominal의 약자), BAA (양의 울음 소리), AA (용암의 종류), ABBA (스웨덴 팝 그룹)이 있다. 이런 사실에 놀란 수빈

www.acmicpc.net

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

int main() {
	string s, t;
	queue <string> q;
	cin >> s;
	cin >> t;
	string front1, front2;
	q.push(t);
	while (!q.empty()) {
		front1 = q.front();
		front2 = q.front();
		if (q.front() == s) {
			cout << 1;
			return 0;
		}
		else if (front1.length() < s.length()) {
			break;
		}

		reverse(front2.begin(), front2.end());

		if (front1[front1.length()-1] == 'A') {
			front1.erase(front1.length() - 1);
			q.push(front1);
		}

		if (front2[front2.length()-1] == 'B') {
			front2.erase(front2.length() - 1);
			q.push(front2);
		}
		q.pop();
	}
	cout << 0;
}

무수한 컴파일 에러의 내용들은 stirng헤더파일의 함수인 pop_back(), back()을 쓰지말라는 내용.

백준에서는 에러를 일으키는 함수인가봐요

그래서 pop_back()은 erase()로 대체하고

back()은 맨끝 인덱스를 따로 구해줌으로써 해결!!

 

 

-------------------------------------------------------------

 

사실 알고보니 c++14로 제출하면 된다하더라

c++ 너무 오래된 버전이라 함수들이 없어서 컴파일에러가 났던거라고 한다,.,.