Source code for submission s585

Go to diff to previous submission

bugs.java

  1.  
  2. import java.util.StringTokenizer;
  3. import java.io.BufferedReader;
  4. import java.io.InputStreamReader;
  5.  
  6. /**
  7.  *
  8.  * @author cteam049
  9.  */
  10. public class bugs {
  11.  
  12. /**
  13.   * @param args the command line arguments
  14.   */
  15. public static void main(String[] args)
  16. {
  17. bugs program = new bugs();
  18. program.run();
  19. }
  20.  
  21. protected void run()
  22. {
  23. try
  24. {
  25. for ( ;; )
  26. {
  27. int lines = this.nextInt();
  28. String replacement = this.nextToken();
  29. // String tmp = this.nextLine();
  30. int pos;
  31. int len = replacement.length();
  32.  
  33. for ( int i = 0; i < lines; i++ )
  34. {
  35. line = new StringBuffer( this.nextLine() );
  36. // line = this.nextLine();
  37. while ( ( pos = line.indexOf( replacement ) ) != -1 )
  38. {
  39. // System.out.println( pos + " " + len );
  40. line.delete( pos, pos + len );
  41. }
  42.  
  43. System.out.println( line );
  44. }
  45. }
  46. } catch ( Exception e )
  47. {
  48. e.printStackTrace();
  49. }
  50. }
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59. /* INPUT READING */
  60.  
  61.  
  62.  
  63.  
  64. public String nextToken() throws Exception
  65. {
  66. while ( ! st.hasMoreTokens() )
  67. {
  68. st = new StringTokenizer( input.readLine() );
  69. }
  70. return st.nextToken();
  71. }
  72.  
  73.  
  74.  
  75. public int nextInt() throws Exception
  76. {
  77. return Integer.parseInt( this.nextToken() );
  78. }
  79.  
  80.  
  81.  
  82. public String nextLine() throws Exception
  83. {
  84. return input.readLine();
  85. }
  86. }
  87.  

Diff to submission s582

bugs.java

--- c4.s582.cteam049.bugs.java.0.bugs.java
+++ c4.s585.cteam049.bugs.java.0.bugs.java
@@ -28,5 +28,5 @@
                 String replacement = this.nextToken();
                 // String tmp = this.nextLine();
-                StringBuilder line;
+                StringBuffer line;
                 int pos;
                 int len = replacement.length();
@@ -34,10 +34,10 @@
                 for ( int i = 0; i < lines; i++ )
                 {
-                    line = new StringBuilder( this.nextLine() );
+                    line = new StringBuffer( this.nextLine() );
                     // line = this.nextLine();
                     while ( ( pos = line.indexOf( replacement ) ) != -1 )
                     {
                         // System.out.println( pos + " " + len );
-                        line = line.delete( pos, pos + len );
+                        line.delete( pos, pos + len );
                     }