题解 | #百钱买百鸡问题#
百钱买百鸡问题
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;
}
}
}
}
}
}
}