// TGPL Chapter 1.3 Finding Duplicate Lines (p. 8 ff.)

// Prints lines from stdin which appear more than once
package dup

import (
	"bufio"
	"fmt"
	"os"
)

// cf. Chap 1.3 p. 9
func Dup1() {
	counts := make(map[string]int) // whew.
	// the map decl syntax is cool.
	// reminds me of "declaration follow use":
	// when i do map["foo"], the output type should be an int
	input := bufio.NewScanner(os.Stdin)

	for input.Scan() { // .Scan() returns true iff there is a line
		counts[input.Text()]++
	}

	for line, n := range counts {
		if n > 1 {
			fmt.Printf("%d duplicates of\t'%s'\n", n, line) // cool, printf!
		}
	}
}
