Source code for submission s582

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. StringBuilder line;
  31. int pos;
  32. int len = replacement.length();
  33.  
  34. for ( int i = 0; i < lines; i++ )
  35. {
  36. line = new StringBuilder( this.nextLine() );
  37. // line = this.nextLine();
  38. while ( ( pos = line.indexOf( replacement ) ) != -1 )
  39. {
  40. // System.out.println( pos + " " + len );
  41. line = line.delete( pos, pos + len );
  42. }
  43.  
  44. System.out.println( line );
  45. }
  46. }
  47. } catch ( Exception e )
  48. {
  49. e.printStackTrace();
  50. }
  51. }
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60. /* INPUT READING */
  61.  
  62.  
  63.  
  64.  
  65. public String nextToken() throws Exception
  66. {
  67. while ( ! st.hasMoreTokens() )
  68. {
  69. st = new StringTokenizer( input.readLine() );
  70. }
  71. return st.nextToken();
  72. }
  73.  
  74.  
  75.  
  76. public int nextInt() throws Exception
  77. {
  78. return Integer.parseInt( this.nextToken() );
  79. }
  80.  
  81.  
  82.  
  83. public String nextLine() throws Exception
  84. {
  85. return input.readLine();
  86. }
  87. }
  88.  

Diff to submission s573

bugs.java

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