package main import ( "os" "bufio" "fmt" "sort" ) type Wc struct { Token string Count int } type ByCount []Wc func (a ByCount) Len() int { return len(a) } func (a ByCount) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a ByCount) Less(i, j int) bool { return a[i].Count > a[j].Count } func main() { var m map[string]int m = make(map[string]int) in := bufio.NewScanner(os.Stdin) in.Split(bufio.ScanWords) for in.Scan() { m[in.Text()] += 1 } var a ByCount; a = make([]Wc, len(m)) i := 0 for key, value := range m { a[i].Token = key a[i].Count = value i += 1 } sort.Sort(ByCount(a)) for _,it := range a { fmt.Println(it.Count," ",it.Token) } // fmt.Println(a) }