守候你守候我
由于您知道定界符并且只有 2 行,因此这也是一个更紧凑的解决方案:package mainimport ( "fmt" "os" "regexp" "strconv" "strings")func main() { parts, err := readRaw("data.txt") if err != nil { panic(err) } n, nums, err := toNumbers(parts) if err != nil { panic(err) } fmt.Printf("%d: %v\n", n, nums)}// readRaw reads the file in input and returns the numbers inside as a slice of stringsfunc readRaw(fn string) ([]string, error) { b, err := os.ReadFile(fn) if err != nil { return nil, err } return regexp.MustCompile(`\s`).Split(strings.TrimSpace(string(b)), -1), nil}// toNumbers plays with the input string to return the data as a slice of intfunc toNumbers(parts []string) (int, []int, error) { n, err := strconv.Atoi(parts[0]) if err != nil { return 0, nil, err } nums := make([]int, 0) for _, p := range parts[1:] { num, err := strconv.Atoi(p) if err != nil { return n, nums, err } nums = append(nums, num) } return n, nums, nil}输出是:5: [2 1 0 3 4]