题解 | #百钱买百鸡问题#
百钱买百鸡问题
http://www.nowcoder.com/practice/74c493f094304ea2bda37d0dc40dc85b
import java.util.Scanner;
/***
* 5a+3b+c/3 = 100 (元)
* a+b+c = 100 (只)
*
*/
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
if(sc.hasNext()){
for(int i=0; i<4; i++){//因为b=25-7a/4,所以要b是正整数的话,a肯定是4的倍数(i倍),由于4*7=28>25, 所以倍数1不大于4;
int a = 4*i;//公鸡
int b = 25-7*i;//母鸡
int c = 100-a-b;//小鸡
System.out.println(a+" "+b+" "+c);
}
}
sc.close();
}
}