Go to diff to previous submission
package javaapplication1; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; public class Bugs { String line; int[] stack = new int[2000000]; while((line = reader.readLine()) != null) { int idx = -1; int state = 0; StringBuilder sb = new StringBuilder(); int c; while(n > 0 && (c = reader.read()) != -1) { if(c == '\n') { n--; } if(bug.charAt(state) == c) { state++; if(state == bug.length()) { if(idx >= 0) { state = stack[idx--]; } else { state = 0; } } } else if(bug.charAt(0) == c) { stack[++idx] = state; state = 1; } else { if(state > 0) { stack[++idx] = state; } for(int i = 0; i <= idx; i++) { state = stack[i]; sb.append(bug.substring(0, state)); } state = 0; idx = -1; sb.append((char) c); } } } } }