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

百钱买百鸡问题

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            String s = sc.next();
            if(s.matches("^-?[1-9]\\d*$")){
                int sum = 100;
                int sCount = 100;
                int xConut = 0;
                for (int gCount = 0; gCount < 20; gCount++) {
                    for (int mCount = 0; mCount < 35; mCount++) {
                        xConut = sCount - gCount - mCount;
                        if((xConut % 3 == 0) && ((5 * gCount + 3 * mCount + xConut / 3) == sum)){
                            System.out.println(gCount + " " + mCount + " " + xConut);
                        }else {
                            continue;
                        }
                    }
                }
            }
        }
    }
}
全部评论

相关推荐

点赞 评论 收藏
分享
吃不饱的肱二头肌很想退休:tnnd 我以为选妹子呢,亏我兴高采烈的冲进来😠
投递快手等公司10个岗位
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务