题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
package main
import (
"bufio"
"fmt"
"os"
"strconv"
)
func main() {
var bottles []int
inputs := bufio.NewScanner(os.Stdin)
for inputs.Scan() {
number, _ := strconv.Atoi(inputs.Text())
if number == 0 {
break
}
bottles = append(bottles, number)
}
for _, bottle := range bottles {
fmt.Println(sudas(bottle))
}
}
func sudas(bottle int) int {
var suda int
for {
m := bottle / 3
if m != 0 {
suda += m
bottle = bottle - 2*m
} else {
n := bottle % 3
if n+1 == 3 {
suda += 1
}
break
}
}
return suda
}