题解 | #汽水瓶#

汽水瓶

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

解题思路
本题主要考察的为取余操作符%,输入的数据是否能被3整除,除不尽的取余加上除数,再和3相除,直到小于3为止;

import java.io.IOException;
import java.util.Scanner;

/**
 * @author Administrator
 */
public class Main  {
    public static void main(String[] args) throws IOException {

        Scanner scanner = new Scanner(System.in);

        while (scanner.hasNext()) {
            int count = 0;
            int input = scanner.nextInt();
            if (input == 0) {
                break;
            }
            while (input != 0) {
                int temp = input / 3;
                count += temp;
                input = input % 3 + temp;
                if (input < 3) {
                    break;
                }
            }
            if (input == 2) {
                count++;
            }

            System.out.println(count);
        }
    }
}
全部评论

相关推荐

不愿透露姓名的神秘牛友
07-31 17:23
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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