9/19 迅雷笔试第二题
分奖金的问题:纯暴力解;给的例子都能过,提交的时候0%???
有大佬帮忙看看不
给出代码:
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { br := bufio.NewReader(os.Stdin) str, _ := br.ReadString('\n') ans := make([]int, 0) strs := strings.Split(str, " ") n := len(strs) for _, s := range strs { tmp, _ := strconv.Atoi(s) ans = append(ans, tmp) } cnt := 0 for i := 1; i < n; i++ { for j := i + 1; j < n; j++ { if Sum(ans[:i]) <= Sum(ans[i:j]) && Sum(ans[i:j]) <= Sum(ans[j:]) { cnt++ } } } fmt.Println(cnt) return } func Sum(nums []int) int { sum := 0 for _, num := range nums { sum += num } return sum }