Source code for submission s1036

Go to diff to previous submission

Bugs.java

  1. import java.util.*;
  2. import java.math.*;
  3. import java.io.*;
  4. import java.text.*;
  5.  
  6.  
  7. public class Bugs {
  8.  
  9. static String line, newline, bug;
  10.  
  11. static long pos,linecount;
  12. static StringTokenizer st;
  13.  
  14. /**
  15.   * @param args the command line arguments
  16.   */
  17. public static void main(String[] args) throws Exception {
  18.  
  19. while( (line=br.readLine()) != null ) {
  20. st = new StringTokenizer(line);
  21. linecount = Long.valueOf(st.nextToken());
  22. bug = st.nextToken();
  23. String mujKrasnyRegex="",druhyLevel=""; // prvni moznost
  24. for (int i = 0; i < bug.length(); i++) {
  25. mujKrasnyRegex+="("+bug+")*"+bug.substring(i, i+1);
  26. }
  27. mujKrasnyRegex+="("+bug+")*";
  28.  
  29. // druhej level
  30. for (int i = 0; i < bug.length(); i++) {
  31. druhyLevel+="("+mujKrasnyRegex+")*"+bug.substring(i, i+1);
  32. }
  33. druhyLevel+="("+mujKrasnyRegex+")*";
  34. druhyLevel="("+druhyLevel+")*";
  35. //System.out.println("bug looks like " + mujKrasnyRegex + "\n"+druhyLevel);
  36. for(long i=0;i<linecount;i++){
  37. line=br.readLine();
  38. //line=line.replaceAll(druhyLevel, "");
  39. while(line.indexOf(bug)!=-1){
  40. //System.out.println("iteruju");
  41. line = line.replaceAll(druhyLevel,"");
  42.  
  43. }
  44.  
  45. out.append(line+"\n");
  46.  
  47.  
  48. }
  49.  
  50.  
  51. }
  52.  
  53. out.close();
  54.  
  55. }
  56.  
  57. }
  58.  

Diff to submission s969

Bugs.java

--- c4.s969.cteam028.bugs.java.0.Bugs.java
+++ c4.s1036.cteam028.bugs.java.0.Bugs.java
@@ -7,4 +7,6 @@
 public class Bugs {
     static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
+    static BufferedWriter out= new BufferedWriter(new OutputStreamWriter(System.out));
+
     static String line, newline, bug;
     
@@ -16,5 +18,6 @@
      */
     public static void main(String[] args) throws Exception {
-        while( (line=br.readLine()) != null) {
+        
+        while( (line=br.readLine()) != null ) {
             st = new StringTokenizer(line);
             linecount = Long.valueOf(st.nextToken());
@@ -39,7 +42,10 @@
                     //System.out.println("iteruju");
                     line = line.replaceAll(druhyLevel,"");
+                    
                 }
                 
-                System.out.println(line);
+                out.append(line+"\n");
+                
+                
             }
             
@@ -47,4 +53,5 @@
         }    
         
+            out.close();
         
     }