题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
package main import ( "bufio" "fmt" "os" "strconv" "strings" ) func main() { input := bufio.NewScanner(os.Stdin) arr := make([]int, 0) for input.Scan() { x, _ := strconv.Atoi(strings.TrimSpace(input.Text())) if x == 0 { break } value := count(x) arr = append(arr, value) } for _, value := range arr { fmt.Println(value) } } func count(x int) int { if x%3 == 1 && x/3 == 0{ return 0 } if x%3 == 2 && x/3 == 0{ return 1 } return x/3 + count(x/3+x%3) }