Source code for submission s881

Go to diff to previous submission

Bugs.java

  1. import java.io.BufferedReader;
  2. import java.io.IOException;
  3. import java.io.InputStreamReader;
  4. import java.util.Scanner;
  5.  
  6. public class Bugs {
  7.  
  8. public static void main(String[] args) throws IOException {
  9.  
  10.  
  11. while (true) {
  12. String vstupRadka = br.readLine();
  13.  
  14. if (vstupRadka == null) {
  15. break;
  16. }
  17.  
  18. Scanner sc = new Scanner(vstupRadka);
  19.  
  20. int n = sc.nextInt();
  21. String slovo = sc.next();
  22.  
  23. for (int i = 0; i < n; i++) {
  24. String radka = br.readLine();
  25.  
  26. if (!radka.contains(slovo)) {
  27. System.out.println(radka);
  28. } else {
  29. String stary = radka;
  30. while (true) {
  31. String novy = stary.replace(slovo, "");
  32. if (novy.equals(stary)) {
  33. System.out.println(novy);
  34. break;
  35. }
  36. stary = novy;
  37. }
  38. }
  39. }
  40. }
  41.  
  42. }
  43.  
  44. }
  45.  

Diff to submission s828

Bugs.java

--- c4.s828.cteam118.bugs.java.0.Bugs.java
+++ c4.s881.cteam118.bugs.java.0.Bugs.java
@@ -28,5 +28,13 @@
                                         System.out.println(radka);
                                 } else {
-                                        System.out.println(radka.replace(slovo, ""));
+                                        String stary = radka;
+                                        while (true) {
+                                                String novy = stary.replace(slovo, "");
+                                                if (novy.equals(stary)) {
+                                                        System.out.println(novy);
+                                                        break;
+                                                }                                               
+                                                stary = novy;                                           
+                                        }
                                 }
                         }