Go to diff to previous submission
import java.io.BufferedReader; /* * To change this template, choose Tools | Templates * and open the template in the editor. */ import java.io.IOException; import java.io.InputStreamReader; import java.util.LinkedList; import java.util.StringTokenizer; /** * * @author cteam022 */ public class Bugs { /** * @param args the command line arguments */ Bugs g = new Bugs(); while(true){g.uloha();} } char[] bug = st.nextToken().toCharArray(); char bugFirst = bug[0]; Item.bug = bug; for (int i = 0; i < lines; i++) { char[] line = input.readLine().toCharArray(); LinkedList<Item> lifo = new LinkedList<Item>(); StringBuilder out = new StringBuilder(); for (int pos = 0; pos < line.length; pos++) { char current = line[pos]; if (current == bugFirst) { lifo.addLast(new Item(current)); } else { if (lifo.isEmpty()) { } else { Item last = lifo.getLast(); if (current == last.getNext()) { last.extend(current); if (last.isBug()) { lifo.removeLast(); } } else { while (!lifo.isEmpty()) { } } } } } while (!lifo.isEmpty()) { } } } static class Item { int length; char[] text; static char[] bug = new char[0]; Item(char first) { text = new char[bug.length]; text[0] = first; length = 1; } boolean isBug() { if (length != bug.length) return false; } void extend(char next) { text[length++] = next; } char getNext() { return bug[length]; } } }
--- c4.s1293.cteam022.bugs.java.0.Bugs.java +++ c4.s1309.cteam022.bugs.java.0.Bugs.java @@ -51,5 +51,5 @@ } else { if (lifo.isEmpty()) { - out.append(current); + System.out.print(current);//out.append(current); } else { Item last = lifo.getLast(); @@ -63,7 +63,7 @@ } else { while (!lifo.isEmpty()) { - out.append(lifo.pollFirst().text); + System.out.print(String.valueOf(lifo.pollFirst().text));//out.append(lifo.pollFirst().text); } - out.append(current); + System.out.print(current);//out.append(current); } } @@ -73,8 +73,8 @@ while (!lifo.isEmpty()) { - out.append(lifo.pollFirst().text); + System.out.print(String.valueOf(lifo.pollFirst().text));//out.append(lifo.pollFirst().text); } - System.out.println(out); + System.out.println();//System.out.println(out); System.out.flush(); @@ -105,5 +105,5 @@ void extend(char next) { text[length++] = next; - } + } char getNext() {