https://www.acmicpc.net/problem/9935
2021 네이버웹툰 코딩테스트 3번이랑 굉장히 유사한 문제이다.
떨어진게 억울해서 복습할 겸 풀어보았다.
슬라이딩윈도우로 구현하였다.
public class BOJ_9935_문자열폭발 {
static StringBuilder sb = new StringBuilder();
static String bomb, str;
static int bomblen;
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
bomb = br.readLine();
bomblen = bomb.length();
for (int i = 0; i < str.length(); i++) {
sb.append(str.charAt(i));
if (sb.length() >= bomblen) {
if (sb.substring(sb.length() - bomblen, sb.length()).equals(bomb)) {
sb.delete(sb.length() - bomblen, sb.length());
}
}
}
System.out.println(sb.length() == 0 ? "FRULA" : sb);
}
}