Source code for submission s627

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

Diff to submission s585

bugs.java

--- c4.s585.cteam049.bugs.java.0.bugs.java
+++ c4.s627.cteam049.bugs.java.0.bugs.java
@@ -23,24 +23,28 @@
         try
         {
+            StringBuffer line = new StringBuffer( 2000000 );
+            int lines;
+            String replacement;
+            int len;
+            int pos;
             for ( ;; )
             {
-                int lines = this.nextInt();
-                String replacement = this.nextToken();
-                // String tmp = this.nextLine();
-                StringBuffer line;
-                int pos;
-                int len = replacement.length();
+                
+                lines = this.nextInt();
+                replacement = this.nextToken();                
+                
+                len = replacement.length();
 
+                
                 for ( int i = 0; i < lines; i++ )
                 {
-                    line = new StringBuffer( this.nextLine() );
-                    // line = this.nextLine();
+                    line.append(this.nextLine());
                     while ( ( pos = line.indexOf( replacement ) ) != -1 )
                     {
-                        // System.out.println( pos + " " + len );
                         line.delete( pos, pos + len );
                     }
 
                     System.out.println( line );
+                    line.delete(0, line.length());
                 }
             }