题解 | #汽水瓶#

汽水瓶

http://www.nowcoder.com/practice/fe298c55694f4ed39e256170ff2c205f

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        
        while(sc.hasNextInt()){
            int n=sc.nextInt();
            if(n==0) break;
            
            int res=0;
            int k;
            
            while(n>1){
                k=n/3;
                res+=k;
                n=n%3+k;
                
                if(n==2){
                    res+=1;
                    break;
                }
            }
            System.out.println(res);
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
05-24 14:12
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务