美文网首页
[Go]疑似bufio bug一例

[Go]疑似bufio bug一例

作者: 钾肥尔德 | 来源:发表于2019-03-06 16:04 被阅读0次

源码:

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    counts := make(map[string]int)
    input := bufio.NewScanner(os.Stdin)
    for input.Scan() {
        counts[input.Text()]++
    }
    for line, n := range counts {
        if n > 1 {
            fmt.Printf("%d\t%s\n", n, line)
        }
    }
}

输出:


图片.png

相关文章

网友评论

      本文标题:[Go]疑似bufio bug一例

      本文链接:https://www.haomeiwen.com/subject/ffcxpqtx.html