Files
learngo/23-input-scanning/exercises/02-unique-words/solution/main.go

29 lines
607 B
Go
Raw Normal View History

2019-04-12 16:55:26 +03:00
// Copyright © 2018 Inanc Gumus
// Learn Go Programming Course
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
//
2019-10-30 19:34:44 +03:00
// For more tutorials : https://learngoprogramming.com
// In-person training : https://www.linkedin.com/in/inancgumus/
// Follow me on twitter: https://twitter.com/inancgumus
package main
2019-04-12 16:55:26 +03:00
import (
"bufio"
"fmt"
"os"
)
func main() {
in := bufio.NewScanner(os.Stdin)
in.Split(bufio.ScanWords)
total, words := 0, make(map[string]int)
for in.Scan() {
total++
words[in.Text()]++
}
fmt.Printf("There are %d words, %d of them are unique.\n",
total, len(words))
}