Source code for submission s1096

Go to diff to previous submission

Bugs.java

  1.  
  2.  
  3.  
  4. import java.io.BufferedReader;
  5. import java.io.IOException;
  6. import java.io.InputStreamReader;
  7. import java.util.LinkedList;
  8.  
  9. public class Bugs {
  10. static public int replace(int offset) {
  11. int hladanyIndex = 0;
  12. int hladanyStart = -1;
  13.  
  14. for(int i=offset; i < co.length; i++) {
  15. char c = co[i];
  16.  
  17. if(c == cim[hladanyIndex]) {
  18. if(hladanyIndex == 0) {
  19. hladanyStart = i;
  20. }
  21. hladanyIndex++;
  22. if(hladanyIndex == cim.length) {
  23. return i-1;
  24. }
  25. } else {
  26. if(c == cim[0]) {
  27. int result = replace(i);
  28. if(result == -1) {
  29. return -1;
  30. } else {
  31. i = result+1;
  32. }
  33. } else {
  34. return -1;
  35. }
  36. }
  37. }
  38.  
  39. return -1;
  40. }
  41.  
  42. static public void replaceTop() {
  43. for(int i=0; i < co.length; i++) {
  44. char c = co[i];
  45.  
  46. if(c == cim[0]) {
  47. int result = replace(i);
  48. if(result != -1) {
  49. i = result+1;
  50. continue;
  51. }
  52. }
  53.  
  54. System.out.print(c);
  55. }
  56. }
  57.  
  58. static public char[] co;
  59. public static char[] cim;
  60. static public LinkedList<int[]> intervaly;
  61.  
  62. public static void main(String[] args) throws IOException {
  63.  
  64. String identifier;
  65.  
  66. while((identifier = reader.readLine()) != null) {
  67. int medzera = identifier.indexOf(" ");
  68. int riadkov = Integer.valueOf(identifier.substring(0, medzera));
  69. char[] hladame = identifier.substring(medzera+1).toCharArray();
  70.  
  71. for(int i=0; i<riadkov; ++i) {
  72. char [] line = reader.readLine().toCharArray();
  73. intervaly = new LinkedList<int[]>();
  74.  
  75. co = line;
  76. cim = hladame;
  77.  
  78. replaceTop();
  79.  
  80. System.out.println();
  81. }
  82. }
  83. }
  84. }
  85.  

Diff to submission s1076

Bugs.java

--- c4.s1076.cteam121.bugs.java.0.Bugs.java
+++ c4.s1096.cteam121.bugs.java.0.Bugs.java
@@ -5,4 +5,5 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
+import java.util.LinkedList;
 
 public class Bugs {
@@ -20,7 +21,4 @@
                 hladanyIndex++;
                 if(hladanyIndex == cim.length) {
-                    for(int j = hladanyStart; j <= i; j++) {
-                        maska[j] = false;
-                    }
                     return i-1;
                 }
@@ -50,6 +48,9 @@
                 if(result != -1) {
                     i = result+1;
+                    continue;
                 }
             }
+            
+            System.out.print(c);
         }
     }
@@ -57,5 +58,5 @@
     static public char[] co;
     public static char[] cim;
-    static public boolean[] maska;
+    static public LinkedList<int[]> intervaly;
     
     public static void main(String[] args) throws IOException {
@@ -71,9 +72,5 @@
             for(int i=0; i<riadkov; ++i) {
                 char [] line = reader.readLine().toCharArray();
-                maska = new boolean[line.length];
-                
-                for(int j=0; j<maska.length; j++) {
-                    maska[j] = true;
-                }
+                intervaly = new LinkedList<int[]>();
                 
                 co = line;
@@ -82,9 +79,4 @@
                 replaceTop();
                 
-                for(int j=0; j<maska.length; j++) {
-                    if(maska[j])
-                        System.out.print(line[j]);
-                }
-                
                 System.out.println();
             }