题解 | #汽水瓶#

汽水瓶

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

给👴气死了

首先,老实人做法,数学题嘛:

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = 0;
        while((i = sc.nextInt()) != 0)
        if(i != 0)
        System.out.println(exchange(i));
    }
    
    public static int exchange(int nums){
        int colar = 0;
        int bottle = 0;
        colar += nums / 3;
        bottle += nums % 3 + colar;
        while(bottle >= 3){
        colar += bottle / 3;
        bottle -= bottle / 3 * 2; //原式:bottle = bottle - bottle / 3 * 3 + bottle / 3
        }
        if(bottle == 2)
            colar ++;
        return colar;
    }
}

但是这tm居然是个脑筋急转弯!

import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int i = 0;
        while((i = sc.nextInt()) != 0)
        if(i != 0)
        System.out.println(i / 2);
    }

}

没错,除以二就是正确答案,吃了没文化的亏。。。

全部评论

相关推荐

只有一个苍穹外卖外加正在看黑马点评,可以找小厂实习吗,还有我的简历有什么大问题吗
Java抽象小篮子:感觉有点熟悉,问题1是学历,2是没实习经历,3是专业技能写得太少太少了(怎么写可以看我置顶帖),4是仅这一个项目找实习不够看。拷打完毕,简历怎么写可以看我置顶帖子
点赞 评论 收藏
分享
完美的潜伏者许愿简历通过:我上表jd,请求封我做后端大将军的事,北京有消息了:竟然不许!!! 他们一定是看我没有实习,这才故意驳回我的请求!
点赞 评论 收藏
分享
评论
1
2
分享

创作者周榜

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