Source code for submission s1076

Bugs.java

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