import java.util.*; import java.io.*; public class Concordance1 { private Dictionary dict = new Hashtable(); public void readLines(BufferedReader 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); while (e.hasMoreElements()) enterWord((String) e.nextElement(), new Integer(line)); } } 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); } if (! set.contains(line)) set.addElement(line); } static public void main(String[] args) { Concordance1 c = new Concordance1(); try { c.readLines(new BufferedReader(new InputStreamReader(System.in))); } catch (IOException e) { return; } c.generateOutput(System.out); } }