Source code for submission s741

Go to diff to previous submission

Bugs.java

  1.  
  2.  
  3. package javaapplication1;
  4.  
  5. import java.io.BufferedReader;
  6. import java.io.IOException;
  7. import java.io.InputStreamReader;
  8.  
  9. public class Bugs {
  10.  
  11. public static void main(String[] args) throws IOException {
  12. String line;
  13.  
  14. int[] stack = new int[2000000];
  15.  
  16. while((line = reader.readLine()) != null) {
  17. String[] split = line.split(" ");
  18.  
  19. int n = Integer.parseInt(split[0]);
  20. String bug = split[1];
  21.  
  22. int idx = -1;
  23. int state = 0;
  24.  
  25. StringBuilder sb = new StringBuilder();
  26.  
  27. int c;
  28. while(n > 0 && (c = reader.read()) != -1) {
  29. if(c == '\n') {
  30. n--;
  31. }
  32.  
  33. if(bug.charAt(state) == c) {
  34. state++;
  35. if(state == bug.length()) {
  36. if(idx >= 0) {
  37. state = stack[idx--];
  38. } else {
  39. state = 0;
  40. }
  41. }
  42. } else if(bug.charAt(0) == c) {
  43. stack[++idx] = state;
  44. state = 1;
  45. } else {
  46. if(state > 0) {
  47. stack[++idx] = state;
  48. }
  49. for(int i = 0; i <= idx; i++) {
  50. state = stack[i];
  51. sb.append(bug.substring(0, state));
  52. }
  53. state = 0;
  54. idx = -1;
  55. sb.append((char) c);
  56. }
  57. }
  58. System.out.println(sb);
  59. }
  60. }
  61.  
  62. }
  63.  

Diff to submission s724

Bugs.java

--- c4.s724.cteam026.bugs.java.0.Bugs.java
+++ c4.s741.cteam026.bugs.java.0.Bugs.java
@@ -30,5 +30,4 @@
                 if(c == '\n') {
                     n--;
-                    sb = new StringBuilder();
                 }
                 
@@ -58,4 +57,5 @@
                 }
             }
+            System.out.println(sb);
         }
     }