java解法(完全按题目思路)
汽水瓶
http://www.nowcoder.com/questionTerminal/fe298c55694f4ed39e256170ff2c205f
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); while(sc.hasNext()){ int n = sc.nextInt(); if(n == 0) return; int sum = 0,yu = 0; while(n >= 3){ yu = n % 3; //加上手里能够换取瓶子的数量 sum += n / 3; //更新每次换取瓶子后所剩瓶子数 n = n / 3 + yu; } if(n == 2){ sum++; } System.out.println(sum); } } }