题解 | #汽水瓶#

汽水瓶

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

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int input = Integer.parseInt(sc.nextLine());
            if (input != 00) {
                printResult(input);
            } else {
                break;
            }

        }
    }

    public static void printResult(int n) {
        int count = 0;
        while (true) {
            int x = n / 3;
            count += x;
            int y = n % 3;
            n = x + y;
            if (n == 2) {
                count++;
                break;
            }
            if (n == 1) {
                break;
            }
        }
        System.out.println(count);
    }
}
全部评论

相关推荐

哞客37422655...:你猜为什么福利这么好还得一直追着你问
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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