Source code for submission s996

Go to diff to previous submission

Main.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package bugs;
  7.  
  8. import java.io.IOException;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author cteam064
  14.  */
  15. public class Main {
  16.  
  17.  
  18. public static char readChar() throws IOException{
  19. byte[]array = new byte[1];
  20. char c;
  21. try{
  22. System.in.read(array);
  23. c = (char) array[0];
  24. return c;
  25. }
  26. catch(IOException e){
  27. System.out.println("fail");
  28. return 0;
  29. }
  30. }
  31.  
  32. public static void main(String[] args) throws IOException {
  33. Scanner scanner = new Scanner(System.in);
  34. int lines;
  35. String delimiter;
  36. String buffer = "";
  37. int j = 0;
  38. while (scanner.hasNextInt()){
  39. lines = scanner.nextInt();
  40. delimiter = scanner.next();
  41. for (int i = 0; i < lines;i++){
  42. char c = readChar();
  43. while(c != '\n'){
  44. if (delimiter.charAt(0) == c){
  45. buffer += c;
  46. while(c != '\n'){
  47. c = readChar();
  48. buffer += c;
  49. while (buffer.length() >= delimiter.length() && buffer.substring(buffer.length() - delimiter.length(), buffer.length()).contains(delimiter)){
  50. buffer = buffer.substring(0, buffer.length() - delimiter.length());
  51. }
  52. if (buffer.isEmpty()){
  53. break;
  54. }
  55. }
  56. System.out.print(buffer);
  57. }
  58. else{
  59. System.out.print(c);
  60. }
  61. c = readChar();
  62. }
  63. System.out.println("");
  64. }
  65.  
  66. }
  67.  
  68. }
  69.  
  70. }
  71.  

Diff to submission s962

Main.java

--- c4.s962.cteam064.bugs.java.0.Main.java
+++ c4.s996.cteam064.bugs.java.0.Main.java
@@ -36,5 +36,5 @@
         String buffer = "";
         int j = 0;
-        while (scanner.hasNext()){
+        while (scanner.hasNextInt()){
             lines = scanner.nextInt();
             delimiter = scanner.next();
@@ -47,6 +47,6 @@
                             c = readChar();
                             buffer += c;
-                            while (buffer.contains(delimiter)){
-                                buffer = buffer.replaceAll(delimiter, "");
+                                while (buffer.length() >= delimiter.length() && buffer.substring(buffer.length() - delimiter.length(), buffer.length()).contains(delimiter)){
+                                    buffer = buffer.substring(0, buffer.length() - delimiter.length());
                             }
                             if (buffer.isEmpty()){