Source code for submission s1264

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. line = br.readLine();
  24. x = 0;
  25. tmp.clear();
  26.  
  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(line.charAt(j));
  50. tmp.clear();
  51. }
  52. }
  53. for (String t : tmp) {
  54. System.out.print(t);
  55. }
  56.  
  57. System.out.println();
  58. }
  59.  
  60. } while (true);
  61.  
  62. }
  63. }
  64.  

Diff to submission s990

Bugs.java

--- c4.s990.cteam018.bugs.java.0.Bugs.java
+++ c4.s1264.cteam018.bugs.java.0.Bugs.java
@@ -9,5 +10,5 @@
     static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
     static ArrayList<String> tmp = new ArrayList<String>();
-    
+
     public static void main(String[] args) throws IOException {
         int x;
@@ -15,27 +16,28 @@
         do {
             String line = br.readLine();
-            if(line == null) {
+            if (line == null) {
                 break;
             }
-            tmp.clear();
             StringTokenizer st = new StringTokenizer(line);
             int lines = Integer.parseInt(st.nextToken());
             String word = st.nextToken();
-            for(int i = 0; i < lines; i++) {
+            for (int i = 0; i < lines; i++) {
                 line = br.readLine();
                 x = 0;
-                for(int j = 0; j < line.length(); j++) {
+                tmp.clear();
+            
+                for (int j = 0; j < line.length(); j++) {
                     c = line.charAt(j);
-                    if (c== (word.charAt(0))) {
-                        tmp.add(c+"");
-                        x=1;
-                    } else if (c== (word.charAt(x))) {
-                        String tempString = tmp.get(tmp.size()-1) + c;
-                        tmp.set(tmp.size()-1, tempString);
+                    if (c == (word.charAt(0))) {
+                        tmp.add(c + "");
+                        x = 1;
+                    } else if (c == (word.charAt(x))) {
+                        String tempString = tmp.get(tmp.size() - 1) + c;
+                        tmp.set(tmp.size() - 1, tempString);
                         x++;
-                        if(x == word.length()) {
-                            tmp.remove(tmp.size() -1);
-                            if(tmp.size() > 0) {
-                                x = tmp.get(tmp.size()-1).length();
+                        if (x == word.length()) {
+                            tmp.remove(tmp.size() - 1);
+                            if (tmp.size() > 0) {
+                                x = tmp.get(tmp.size() - 1).length();
                             } else {
                                 x = 0;
@@ -44,5 +46,5 @@
                     } else {
                         x = 0;
-                        for(String t: tmp) {
+                        for (String t : tmp) {
                             System.out.print(t);
                         }
@@ -51,10 +53,13 @@
                     }
                 }
+                for (String t : tmp) {
+                    System.out.print(t);
+                }
+
                 System.out.println();
             }
-            
-        } while(true);
-        
+
+        } while (true);
+
     }
-    
 }