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

百钱买百鸡问题

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            scanner.next();
            //HJ72 百钱买百鸡 公鸡 母鸡 小鸡
            //5x+3y+1/3z=100 x+y+z=100
            int y;
            int x;
            int z;
            for (x = 0; x <= 100; x++) {
                for (y = 0; y <= 100; y++) {
                    if ((100 - x - y) % 3 == 0) {
                        if (5 * x + (3 * y) + (100 - x - y) / 3 == 100 && x + y <= 100) {
                            z = 100 - y - x;
                            System.out.print(x + " " + y + " " + z);
                            System.out.println();
                        }
                    }
                }
            }
        }

    }

}

全部评论

相关推荐

07-09 15:55
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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