Source code for submission s962

Main.java

  1. /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6. package bugs;
  7.  
  8. import java.io.IOException;
  9. import java.util.Scanner;
  10.  
  11. /**
  12.  *
  13.  * @author cteam064
  14.  */
  15. public class Main {
  16.  
  17.  
  18. public static char readChar() throws IOException{
  19. byte[]array = new byte[1];
  20. char c;
  21. try{
  22. System.in.read(array);
  23. c = (char) array[0];
  24. return c;
  25. }
  26. catch(IOException e){
  27. System.out.println("fail");
  28. return 0;
  29. }
  30. }
  31.  
  32. public static void main(String[] args) throws IOException {
  33. Scanner scanner = new Scanner(System.in);
  34. int lines;
  35. String delimiter;
  36. String buffer = "";
  37. int j = 0;
  38. while (scanner.hasNext()){
  39. lines = scanner.nextInt();
  40. delimiter = scanner.next();
  41. for (int i = 0; i < lines;i++){
  42. char c = readChar();
  43. while(c != '\n'){
  44. if (delimiter.charAt(0) == c){
  45. buffer += c;
  46. while(c != '\n'){
  47. c = readChar();
  48. buffer += c;
  49. while (buffer.contains(delimiter)){
  50. buffer = buffer.replaceAll(delimiter, "");
  51. }
  52. if (buffer.isEmpty()){
  53. break;
  54. }
  55. }
  56. System.out.print(buffer);
  57. }
  58. else{
  59. System.out.print(c);
  60. }
  61. c = readChar();
  62. }
  63. System.out.println("");
  64. }
  65.  
  66. }
  67.  
  68. }
  69.  
  70. }
  71.