Source code for submission s643

Bugs.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5. import java.util.*;
  6. import java.io.*;
  7. import java.util.regex.Pattern;
  8. /**
  9.  *
  10.  * @author cteam040
  11.  */
  12. public class Bugs {
  13. public static void main(String[] s) throws Exception
  14. {
  15. String ln;
  16.  
  17. while((ln = br.readLine())!= null) {
  18. st = new StringTokenizer(ln);
  19. int lineCount = Integer.parseInt(st.nextToken());
  20. String bugString = st.nextToken();
  21. //char[] debugArr = bugString.toCharArray();
  22. Pattern ptrn = Pattern.compile(bugString);
  23. for (int i = 0; i < lineCount; i++) {
  24. // String line =
  25.  
  26. int newLen = - 1;
  27. String debugedLine = br.readLine();
  28. int len = debugedLine.length();
  29. // String debugedLine = debug(line, debugArr);
  30. // int size = debugedLine.length();
  31. // int oldSize
  32. while(newLen != len) {
  33. // System.out.println(debugedLine);
  34. len = newLen;
  35. debugedLine = ptrn.matcher(debugedLine).replaceAll("");
  36. //debugedLine = debugedLine.replaceAll(bugString, "");//debug(debugedLine, debugArr);
  37. newLen = debugedLine.length();
  38. }
  39. System.out.println(debugedLine);
  40. }
  41.  
  42. }
  43. }
  44.  
  45. private static String debug(String line, char[] debugArr) {
  46. char[] lineArr = line.toCharArray();
  47. int bugIndex = 0;
  48. StringBuilder builder = new StringBuilder();
  49. List<Character> temp = new LinkedList<Character>();
  50.  
  51. for (int i = 0; i < lineArr.length; i++) {
  52. char c = lineArr[i];
  53.  
  54.  
  55. if(bugIndex + 1 == debugArr.length) {
  56. temp = new LinkedList<Character>();
  57. bugIndex = 0;
  58. continue;
  59. }
  60. if(c == debugArr[bugIndex]) {
  61. bugIndex++;
  62. temp.add(c);
  63. } else {
  64. bugIndex = 0;
  65. for(char a: temp){
  66. builder.append(a);
  67. }
  68. temp = new LinkedList<Character>();
  69. builder.append(c);
  70. }
  71.  
  72.  
  73.  
  74. }
  75. return builder.toString();
  76. }
  77.  
  78. }
  79.