#include <iostream>
#include <cstring>
#include <stack>
#include <vector>
using namespace std;
void solution(string input, string exp){
stack<char> s;
vector<char> v;
string answer;
for (int i = (int)input.length(); i >= 0; i--) {
s.push(input[i-1]);
if (s.size() >= exp.length()){ // s의 사이즈가 폭발 문자열의 길이와 같거나 커짐
for (int j = 0; j < exp.length(); ++j) { // top부터 폭발 문자열 문자 하나씩 비교
if (s.top() == exp[j]) { // 같을 경우
v.push_back(s.top());
s.pop();
} else { // 다를 경우
if (v.size() != 0) {
while (!v.empty()) {
s.push(v.back());
v.pop_back();
}
} else {
break;
}
}
} // for
v.clear();
} // if
} // for
s.pop(); // char 뒤에 붙는 이상한 이스케이프 시퀀스 없앰
if (s.empty()) {
answer += "FRULA";
} else {
while (!s.empty()) {
answer += s.top();
s.pop();
}
}
cout << answer << endl;
} // solution()
int main(){
string input, explosion;
cin >> input >> explosion;
solution(input, explosion);
return 0;
}
개재밌다.
스택 문제 조진다 ㄱㄱ