package main
import (
"fmt"
"strconv"
"strings"
)
func main() {
var inputStr string
fmt.Scan(&inputStr)
scoreStrs := strings.Split(inputStr, ",")
n := len(scoreStrs)
scores := make([]int, n)
for i, scoreStr := range scoreStrs {
scores[i], _ = strconv.Atoi(scoreStr)
}
sumScoreList := make([]int, n)
sumScore := 0
//开始执行n轮选牌
for i := 0; i < n; i++ {
//前三轮
if i < 3 {
if sumScore+scores[i] < 0 {
//跳过,不选牌
sumScore = 0
sumScoreList[i] = sumScore
continue
} else {
sumScore += scores[i]
sumScoreList[i] = sumScore
}
} else {
tempSumScore := sumScoreList[i-3]
if sumScore+scores[i] < tempSumScore {
//跳过,不选牌
sumScore = tempSumScore
sumScoreList[i] = sumScore
continue
} else {
sumScore += scores[i]
sumScoreList[i] = sumScore
}
}
}
fmt.Println(sumScore)
}
【华为OD机试真题】81、玩牌高手 (100分)
最新推荐文章于 2024-11-11 10:20:49 发布