Source code for submission s1245

Go to diff to previous submission

Bugs.java

  1. import java.io.BufferedReader;
  2.  
  3. /*
  4.  * To change this template, choose Tools | Templates
  5.  * and open the template in the editor.
  6.  */
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9.  
  10. class Bugs {
  11.  
  12. /**
  13.   * @param args the command line arguments
  14.   */
  15. public static void main(String[] args) throws IOException {
  16. while(true){
  17. String firstLine = br.readLine();
  18. if(firstLine == null) return;
  19. String [] firstWords = firstLine.split(" ");
  20. int lineCount = Integer.parseInt(firstWords[0]);
  21.  
  22. String errorCode = firstLine.substring(firstWords[0].length() + 1);
  23. // System.out.println(errorCode + " " + errorCode.length());
  24. int errorCodeLength = errorCode.length();
  25. String line = "";
  26.  
  27. for (int i = 0; i < lineCount; i++) {
  28. line = br.readLine();
  29. if(line.length() >= errorCodeLength){
  30. while(line.contains(errorCode)){
  31. int position = line.indexOf(errorCode);
  32. line = line.substring(0, position) +
  33. line.substring(position + errorCodeLength);
  34. }
  35. }
  36. System.out.println(line);
  37. }
  38. }
  39.  
  40. }
  41.  
  42. }
  43.  

Diff to submission s725

Bugs.java

--- c4.s725.cteam037.bugs.java.0.Bugs.java
+++ c4.s1245.cteam037.bugs.java.0.Bugs.java
@@ -30,6 +30,7 @@
                                 if(line.length() >= errorCodeLength){
                 while(line.contains(errorCode)){
-
-                        line = line.replaceAll(errorCode, "");
+                                                int position = line.indexOf(errorCode);
+                        line = line.substring(0, position) +
+                                                                        line.substring(position + errorCodeLength);
                 }
                                 }