使用解方程的解法,一次循环就可以了
百钱买百鸡问题
http://www.nowcoder.com/questionTerminal/74c493f094304ea2bda37d0dc40dc85b
while True:
    try:
        n = int(input())
        # 鸡公最多买20只
        for x in range(21):
            y = (100-7*x)/4  # 鸡母的数量
            z = 100 - x - y  # 鸡雏的数量
            if y == int(y) and y >= 0 and z >= 0:
                print(x, int(y), int(z))
    except EOFError:
        break

 查看12道真题和解析
查看12道真题和解析 联想公司福利 1500人发布
联想公司福利 1500人发布