import java.io.*;
import java.util.Hashtable;
import java.util.Enumeration;

class WordCount {

    public static void main(String[] args) {

	Hashtable table = new Hashtable();

	try {
	    InputStream in;
	    if (args.length < 1)
		in = System.in;
	    else
		in = new FileInputStream(args[0]);

	    StreamTokenizer tokens = new StreamTokenizer(in);
	    tokens.ordinaryChar('.'); // prevent period from being part of word
	    tokens.ordinaryChar('"'); // don't handle quotes or comments
	    tokens.ordinaryChar('\'');
	    tokens.ordinaryChar('/');

	    while (tokens.nextToken() != StreamTokenizer.TT_EOF) {
		if (tokens.ttype == StreamTokenizer.TT_WORD) {
		    String word =	// always convert to lower case
			tokens.sval.toLowerCase();
		    Count count = (Count)table.get(word);  // look up word
		    if (count == null) {
			count = new Count();	   // create new count object
			table.put(word, count);    // if first word occurrence
		    }
		    count.increment();
		}
	    }
	} catch (IOException e) {
	    error("I/O Exception: " + e);
	}

	// print out the words and associated counts
	Enumeration enum = table.keys();
	while (enum.hasMoreElements()) {
	    String word = (String)enum.nextElement();
	    int count = ((Count)table.get(word)).getCount();
	    System.out.println(word + ": " + count);
	}
    }

    public static void error(String err) {
	System.err.println("WordCount: " + err);
	System.exit(1); // non-zero argument means "not good"
    }
}

class Count {
    private int count = 0;

    public void increment() {
	count++;
    }

    public int getCount() {
	return count;
    }
}
