Source code for submission s1340

Go to diff to previous submission

Bugs.java

  1.  
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.util.ArrayList;
  6. import java.util.StringTokenizer;
  7.  
  8. public class Bugs {
  9.  
  10. static ArrayList<String> tmp = new ArrayList<String>();
  11.  
  12. public static void main(String[] args) throws IOException {
  13. int x;
  14. char c;
  15. do {
  16. String line = br.readLine();
  17. if (line == null) {
  18. break;
  19. }
  20. int lines = Integer.parseInt(st.nextToken());
  21. String word = st.nextToken();
  22. for (int i = 0; i < lines; i++) {
  23. c = (char) br.read();
  24. x = 0;
  25. tmp.clear();
  26. while (c != Character.LINE_SEPARATOR) {
  27. //for (int j = 0; j < line.length(); j++) {
  28. //c = line.charAt(j);
  29. if (c == (word.charAt(0))) {
  30. tmp.add(c + "");
  31. x = 1;
  32. } else if (c == (word.charAt(x))) {
  33. String tempString = tmp.get(tmp.size() - 1) + c;
  34. tmp.set(tmp.size() - 1, tempString);
  35. x++;
  36. if (x == word.length()) {
  37. tmp.remove(tmp.size() - 1);
  38. if (tmp.size() > 0) {
  39. x = tmp.get(tmp.size() - 1).length();
  40. } else {
  41. x = 0;
  42. }
  43. }
  44. } else {
  45. x = 0;
  46. for (String t : tmp) {
  47. System.out.print(t);
  48. }
  49. System.out.print(c);
  50. tmp.clear();
  51. }
  52. c = (char) br.read();
  53.  
  54. }
  55. for (String t : tmp) {
  56. System.out.print(t);
  57. }
  58.  
  59. System.out.println();
  60. }
  61.  
  62. } while (true);
  63.  
  64. }
  65. }
  66.  

Diff to submission s1264

Bugs.java

--- c4.s1264.cteam018.bugs.java.0.Bugs.java
+++ c4.s1340.cteam018.bugs.java.0.Bugs.java
@@ -23,10 +23,10 @@
             String word = st.nextToken();
             for (int i = 0; i < lines; i++) {
-                line = br.readLine();
+                c = (char) br.read();
                 x = 0;
                 tmp.clear();
-            
-                for (int j = 0; j < line.length(); j++) {
-                    c = line.charAt(j);
+                while (c != Character.LINE_SEPARATOR) {
+                //for (int j = 0; j < line.length(); j++) {
+                    //c = line.charAt(j);
                     if (c == (word.charAt(0))) {
                         tmp.add(c + "");
@@ -49,7 +49,9 @@
                             System.out.print(t);
                         }
-                        System.out.print(line.charAt(j));
+                        System.out.print(c);
                         tmp.clear();
                     }
+                c = (char) br.read();
+                
                 }
                 for (String t : tmp) {