Source code for submission s990

Bugs.java

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