Go to diff to previous submission
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.StringTokenizer; public class Bugs { static ArrayList<String> tmp = new ArrayList<String>(); int x; char c; do { if (line == null) { break; } for (int i = 0; i < lines; i++) { line = br.readLine(); x = 0; 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))) { 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(); } else { x = 0; } } } else { x = 0; } tmp.clear(); } } } } } while (true); } }
--- 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); + } - }