update: log parser dir to input scanning
This commit is contained in:
27
23-input-scanning/exercises/02-unique-words/solution/main.go
Normal file
27
23-input-scanning/exercises/02-unique-words/solution/main.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package main
|
||||
|
||||
// For more tutorials: https://blog.learngoprogramming.com
|
||||
//
|
||||
// Copyright © 2018 Inanc Gumus
|
||||
// Learn Go Programming Course
|
||||
// License: https://creativecommons.org/licenses/by-nc-sa/4.0/
|
||||
//
|
||||
|
||||
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))
|
||||
}
|
Reference in New Issue
Block a user