题解 | #百钱买百鸡问题#

百钱买百鸡问题

http://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b


// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        in.nextInt();
        int x = 0,y = 0,z = 0;
        // 5x + 3y + z/3 = 100
        // x + y + z = 100
        // 3y + 7z = 600
        // i表示小鸡数量,必须是3的倍,不然钱不是整数
        for (int i = 0; i < 100; i+=3) {
            z = i;
            y = (600 - 7*z)/3;
            x = 100 - z - y;
            if (y < 0 || x < 0){
                continue;
            }
            System.out.println(x + " " + y + " " + z);
        }
    }
}
全部评论

相关推荐

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

创作者周榜

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