请问这个读取输入错误的问题是在哪呀? package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { scanner := bufio.NewScanner(os.Stdin) scanner.Scan() str := scanner.Text() strArray := strings.Split(str, " ") n, _ := strconv.Atoi(strArray[0]) scanner.Scan() str = scanner.Text() strArray = strings.Split(str, " ") nums := make([]int, n) res := 0 ans := 0 for i := 0; i < n; i++{ nums[i], _ = strconv.Atoi(strArray[i]) res += nums[i] if nums[i] == 0{ ans++ } } for scanner.Scan(){ str = scanner.Text() strArray = strings.Split(str, " ") min, _ := strconv.Atoi(strArray[0]) max, _ := strconv.Atoi(strArray[1]) fmt.Printf("%v %v\n", res + min * ans, res + max * ans) } } 程序异常退出, 请检查代码"是否有数组越界等异常"或者"是否有语法错误" panic: runtime error: index out of range [1] with length 1 goroutine 1 [running]: main.main() /tmp/main.go:44 +0x34a
点赞 1

相关推荐

牛客网
牛客企业服务