穷举法,百钱百鸡问题。鸡翁一,值钱五;鸡母一,值钱三;鸡雏三,值钱一;百钱买百鸡,翁、母、雏各几何? **输出格式要求:"%2d:cock=%2d hen=%2d chicken=%2d\n"
时间: 2023-05-30 13:06:18 浏览: 147
百钱买百鸡问题
```python
for cock in range(0, 21):
for hen in range(0, 34):
chicken = 100 - cock - hen
if (5 * cock + 3 * hen + chicken // 3) == 100 and chicken % 3 == 0:
print("-:cock={0} - hen={1} - chicken={2}".format(cock, hen, chicken))
```
输出结果为:
```
-:cock=0 - hen=25 - chicken=75
-:cock=4 - hen=18 - chicken=78
-:cock=8 - hen=11 - chicken=81
-:cock=12 - hen=4 - chicken=84
```
阅读全文