题解 | #百钱买百鸡问题#
百钱买百鸡问题
http://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); while (in.hasNextInt()) { int invalid = in.nextInt(); for (int male = 0; male <= 20; male++) { // 公鸡1个5元 100元最多能买20个 for (int female = 0; female <= 33; female++) { // 母鸡值3 33*3 int left = (100 - male * 5 - female * 3);//买公鸡 和 母鸡后的余额 if (left > 0 && male+female+left*3 ==100){ System.out.println(male + " " + female + " " + left*3);//鸡雏 值1/3 1元能买3个 } } } } } }