Source code for submission s819

Bugs.java

  1.  
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5.  
  6. /**
  7.  *
  8.  * @author cteam095
  9.  */
  10. public class Bugs {
  11.  
  12. /**
  13.   * @param args the command line arguments
  14.   */
  15. public static void main(String[] args) throws IOException {
  16.  
  17.  
  18. String inputLine = br.readLine();
  19.  
  20.  
  21. while (inputLine != null) {
  22.  
  23. String[] split = inputLine.split(" ");
  24.  
  25. int lines = Integer.parseInt(split[0]);
  26.  
  27. String pattern = split[1];
  28. String firstChar = String.valueOf(pattern.charAt(0));
  29. String lastChar = String.valueOf(pattern.charAt(pattern.length() - 1));
  30.  
  31. for (int i = 0; i < lines; i++) {
  32. //String line = "printfBUG(\"Hello,world!\\n\");";
  33.  
  34. String line = br.readLine();
  35.  
  36. String temp = line;
  37. String prefix = "";
  38. String suffix = "";
  39.  
  40. int indexOf = temp.indexOf(firstChar);
  41. int indexOf2 = temp.lastIndexOf(lastChar);
  42.  
  43.  
  44. int oldLength;
  45. while (indexOf != -1 && indexOf2 != -1) {
  46.  
  47. prefix = prefix + temp.substring(0, indexOf);
  48. suffix = temp.substring(indexOf2 + 1)+suffix ;
  49. temp = temp.substring(indexOf, indexOf2 + 1);
  50.  
  51.  
  52. oldLength = temp.length();
  53. temp = temp.replaceAll(pattern, "");
  54. if (temp.length() == oldLength) {
  55. break;
  56. }
  57.  
  58. indexOf = temp.indexOf(firstChar);
  59. indexOf2 = temp.lastIndexOf(lastChar);
  60.  
  61. };
  62.  
  63.  
  64.  
  65. System.out.println(prefix + temp + suffix);
  66.  
  67. }
  68. inputLine = br.readLine();
  69. }
  70. }
  71. }
  72.