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

百钱买百鸡问题

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            for (int x = 0; x < 20; x++) {
                for (int y = 0; y <= 34; y++) {
                    for (int z = 0; z < 100; z++) {
                        if ((5 * x + 3 * y + z / 3) == 100 && (x + y + z) == 100&&z%3==0) {
                            System.out.println(x + " " + y+" " + z);
                        }
                    }
                }
            }
        }
    }
}

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int a = in.nextInt();
            for (int x = 0; x < 20; x++) {
                for (int y = 0; y <= 34; y++) {
                        if ((7* x + 4 * y ) == 100 ) {
                            System.out.println(x + " " + y+" " + (100-x-y));
                        }
                }
            }
        }
    }
}

全部评论

相关推荐

如题
投递阿里巴巴集团等公司10个岗位 >
点赞 评论 收藏
分享
有担当的灰太狼又在摸鱼:零帧起手查看图片
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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