fix: typos in input scanning
This commit is contained in:
@ -14,12 +14,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
// Create a new scanner that scans from the standard-input
|
|
||||||
in := bufio.NewScanner(os.Stdin)
|
|
||||||
|
|
||||||
// Simulate an error
|
// Simulate an error
|
||||||
// os.Stdin.Close()
|
// os.Stdin.Close()
|
||||||
|
|
||||||
|
// Create a new scanner that scans from the standard-input
|
||||||
|
in := bufio.NewScanner(os.Stdin)
|
||||||
|
|
||||||
// Stores the total number of lines in the input
|
// Stores the total number of lines in the input
|
||||||
var lines int
|
var lines int
|
||||||
|
|
||||||
@ -32,10 +32,9 @@ func main() {
|
|||||||
// fmt.Println("Scanned Bytes:", in.Bytes())
|
// fmt.Println("Scanned Bytes:", in.Bytes())
|
||||||
in.Text()
|
in.Text()
|
||||||
}
|
}
|
||||||
fmt.Printf("There %d lines.\n", lines)
|
fmt.Printf("There are %d line(s)\n", lines)
|
||||||
|
|
||||||
err := in.Err()
|
if err := in.Err(); err != nil {
|
||||||
if err != nil {
|
|
||||||
fmt.Println("ERROR:", err)
|
fmt.Println("ERROR:", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -23,15 +23,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
query := args[0]
|
query := args[0]
|
||||||
|
|
||||||
|
rx := regexp.MustCompile(`[^a-z]+`)
|
||||||
|
|
||||||
in := bufio.NewScanner(os.Stdin)
|
in := bufio.NewScanner(os.Stdin)
|
||||||
in.Split(bufio.ScanWords)
|
in.Split(bufio.ScanWords)
|
||||||
|
|
||||||
rx := regexp.MustCompile(`[^a-z]+`)
|
|
||||||
|
|
||||||
words := make(map[string]bool)
|
words := make(map[string]bool)
|
||||||
for in.Scan() {
|
for in.Scan() {
|
||||||
word := strings.ToLower(in.Text())
|
word := strings.ToLower(in.Text())
|
||||||
word = rx.ReplaceAllString(word, "")
|
word = rx.ReplaceAllString(word, "")
|
||||||
|
|
||||||
if len(word) > 2 {
|
if len(word) > 2 {
|
||||||
words[word] = true
|
words[word] = true
|
||||||
}
|
}
|
||||||
@ -45,7 +46,7 @@ func main() {
|
|||||||
fmt.Printf("The input contains %q.\n", query)
|
fmt.Printf("The input contains %q.\n", query)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
fmt.Printf("Sorry. The input does contain %q.\n", query)
|
fmt.Printf("Sorry. The input does not contain %q.\n", query)
|
||||||
|
|
||||||
// query := "sun"
|
// query := "sun"
|
||||||
// fmt.Println("sun:", words["sun"], "tesla:", words["tesla"])
|
// fmt.Println("sun:", words["sun"], "tesla:", words["tesla"])
|
||||||
@ -55,5 +56,5 @@ func main() {
|
|||||||
// fmt.Printf("The input contains %q.\n", query)
|
// fmt.Printf("The input contains %q.\n", query)
|
||||||
// return
|
// return
|
||||||
// }
|
// }
|
||||||
// fmt.Printf("Sorry. The input does contain %q.\n", query)
|
// fmt.Printf("Sorry. The input does not contain %q.\n", query)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user