https://www.acmicpc.net/problem/9935
public class BOJ9935 {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String word= br.readLine();
String bomb = br.readLine();
int t = bomb.length();
Stack<Character> st = new Stack<>();
for (int i = 0; i <word.length() ; i++) {
st.push(word.charAt(i));
//스택에 값을 넣고 BOMB이랑 사이즈가 같아지면 비교
if(st.size() >= t){
boolean check =true;
for (int j = 0; j < t; j++) {
int index =st.size()-t;
if(st.get(index + j) != bomb.charAt(j)){
check = false;
break;
}
}
// check 후 true 면 pop();
if(check){
for (int j = 0; j < t; j++) {
st.pop();
}
}
}
}
//스택에 남아있는 애들 출력
StringBuilder sb = new StringBuilder();
for (Character c: st){
sb.append(c);
}
System.out.println(sb.length() > 0 ? sb.toString() : "FRULA" );
}
}