package main

import (
	"fmt"
	"strings"
)

func main() {
	// 1) 统计每个单词出现次数
	counts := make(map[string]int)

	// 2) 直接内置 3 行文本，不再从标准输入读
	lines := []string{
		"go is fun",
		"go go go",
		"python is fun too",
	}

	// 3) 逐行逐词统计
	for _, line := range lines {
		for _, word := range strings.Fields(line) {
			counts[word]++
		}
	}

	// 4) 打印单词 → 次数
	for w, c := range counts {
		fmt.Printf("%q 出现了 %d 次\n", w, c)
	}

	// 5) 再建一个 map：单词 → 出现过的行号
	index := make(map[string][]int)
	for lineno, line := range lines {
		for _, word := range strings.Fields(line) {
			index[word] = append(index[word], lineno+1)
		}
	}
	fmt.Println(index)
}
