add: new input scanning exercises
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
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"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in := bufio.NewScanner(os.Stdin)
|
||||
in.Split(bufio.ScanWords)
|
||||
|
||||
rx := regexp.MustCompile(`[^A-Za-z]+`)
|
||||
|
||||
total, words := 0, make(map[string]int)
|
||||
for in.Scan() {
|
||||
total++
|
||||
|
||||
word := rx.ReplaceAllString(in.Text(), "")
|
||||
word = strings.ToLower(word)
|
||||
words[word]++
|
||||
}
|
||||
|
||||
fmt.Printf("There are %d words, %d of them are unique.\n",
|
||||
total, len(words))
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
Come, night. Come, Romeo. Come, thou day in night,
|
||||
For thou wilt lie upon the wings of night
|
||||
Whiter than new snow upon a raven’s back.
|
||||
Come, gentle night, come, loving, black-browed night,
|
||||
Give me my Romeo. And when I shall die,
|
||||
Take him and cut him out in little stars,
|
||||
And he will make the face of heaven so fine
|
||||
That all the world will be in love with night
|
||||
And pay no worship to the garish sun.
|
||||
Oh, I have bought the mansion of a love,
|
||||
But not possessed it, and though I am sold,
|
||||
Not yet enjoyed.
|
Reference in New Issue
Block a user