on
[백준][JAVA] 9935 : 문자열 폭발
[백준][JAVA] 9935 : 문자열 폭발
728x90
https://www.acmicpc.net/problem/9935
import java.io.BufferedReader; import java.io.InputStreamReader; import java.io.IOException; import java.util.Stack; public class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String origin = br.readLine(); String explo = br.readLine(); Stack stack = new Stack(); //초기 문자열의 가장 마지막부터 stack에 push 한다. for(int i=origin.length()-1; i>-1; i--) { stack.push(origin.charAt(i)); if(stack.size()>=explo.length()&&stack.peek;()==explo.charAt(0)){ //stack의 크기가 폭탄 문자열 크기 이상, stack의 top과 폭탄 문자열의 첫 글자가 같은 경우 boolean flag = true; for(int j=1; j 0) sb.append(stack.pop()); } System.out.println(sb); } }
728x90
from http://mingmeng030.tistory.com/170 by ccl(A) rewrite - 2021-09-11 14:27:15