ch4/ch4-03 #157
Replies: 11 comments 5 replies
-
ages["bob"] = ages["bob"] + 1 // happy birthday! |
Beta Was this translation helpful? Give feedback.
-
gopl.io/ch4/graph 突然抛出个2维Map表示很懵逼 |
Beta Was this translation helpful? Give feedback.
-
4.8
|
Beta Was this translation helpful? Give feedback.
-
4.9
|
Beta Was this translation helpful? Give feedback.
-
就不能多加个set类型,搞得这么麻烦 |
Beta Was this translation helpful? Give feedback.
-
4.9 package main
import (
"bufio"
"fmt"
_ "io"
"os"
_ "unicode"
_ "unicode/utf8"
)
func wordfreq() {
counter := make(map[string]int)
scanner := bufio.NewScanner(os.Stdin)
scanner.Split(bufio.ScanWords)
for scanner.Scan() {
word := scanner.Text()
counter[word]++
fmt.Println(counter[word])
}
if err := scanner.Err(); err != nil {
fmt.Printf("Invalid input: %s", err)
}
}
func main() {
wordfreq()
} |
Beta Was this translation helpful? Give feedback.
-
equal(map[string]int{"A": 0}, map[string]int{"B": 42}) |
Beta Was this translation helpful? Give feedback.
-
要是from这个key不存在,hasEdge不会panic吗?不是很懂 |
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
// 练习 4.8: 修改charcount程序,使用unicode.IsLetter等相关的函数,统计字母、数字等Unicode中不同的字符类别。 import ( func main() {
} |
Beta Was this translation helpful? Give feedback.
-
// 练习 4.9: 编写一个程序wordfreq程序,报告输入文本中每个单词出现的频率。在第一次调用Scan前先调用input.Split(bufio.ScanWords)函数,这样可以按单词而不是按行输入。 import ( func main() { } func wordfreq(r io.Reader) map[string]int { |
Beta Was this translation helpful? Give feedback.
-
ch4/ch4-03
中文版
https://gopl-zh.github.io/ch4/ch4-03.html
Beta Was this translation helpful? Give feedback.
All reactions