import java.util.*; import java.io.*; public class FasterConcordance { private Dictionary dict = new Hashtable(); public void readLines(DataInputStream input) throws IOException { String delims = " \t\n.,!?;:()"; for(int line = 1; true; line++) { String text = input.readLine(); if (text == null) return; text = text.toLowerCase(); Enumeration e = new StringTokenizer(text, delims); Integer i = new Integer(line); while (e.hasMoreElements()) enterWord((String) e.nextElement(), i); } } public void generateOutput(PrintStream output) { Enumeration e = dict.keys(); while (e.hasMoreElements()) { String word = (String) e.nextElement(); Vector set = (Vector) dict.get(word); output.print(word + ": "); Enumeration f = set.elements(); while (f.hasMoreElements()) output.print(f.nextElement() + " "); output.println(""); } } private void enterWord(String word, Integer line) { Vector set = (Vector) dict.get(word); if (set == null) { set = new Vector(); dict.put(word,set); set.addElement(line); } else if (set.lastElement() != line) set.addElement(line); } static public void main(String[] args) { FasterConcordance c = new FasterConcordance(); try { c.readLines(new DataInputStream(System.in)); } catch (IOException e) { return; } c.generateOutput(System.out); } }