题解 | #汽水瓶#
汽水瓶
https://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f
package main import ( "fmt" ) func drinkWater(emptyCup int) int { var drinkCup int for emptyCup >= 3 { drinkCup += emptyCup / 3 emptyCup = emptyCup % 3 + emptyCup / 3 // fmt.Printf("drink: %d, emptyCup: %d\n", drinkCup, emptyCup) } if emptyCup == 2 { drinkCup++ } return drinkCup } func main() { for true { var emptyCup int fmt.Scan(&emptyCup) if emptyCup == 0 { break } fmt.Println(drinkWater(emptyCup)) } }
// 本题每行输入为一个整数,所以采用: fmt.Scan(&n)