<!DOCTYPE html>
<html lang="en">
<html lang="en">
<head>
<meta charset="UTF-8">
<title>百钱百鸡</title>
</head>
<meta charset="UTF-8">
<title>百钱百鸡</title>
</head>
<body>
<script>
for (var n = 0; n <= 20; n++) { //公鸡
for (var i = 0; i <= 33; i++) { //母鸡
for (var m = 0; m <= 100; m++) { //小鸡
// n + i + m == 100;,,百鸡
// 5 * n + 3 * i + m / 3 == 100;,,百钱
if ((n + i + m == 100) && (5 * n + 3 * i + m / 3 == 100)) {
document.write('公鸡' + n + ",母鸡" + i + ',小鸡' + m)
}
}
}
}
<script>
for (var n = 0; n <= 20; n++) { //公鸡
for (var i = 0; i <= 33; i++) { //母鸡
for (var m = 0; m <= 100; m++) { //小鸡
// n + i + m == 100;,,百鸡
// 5 * n + 3 * i + m / 3 == 100;,,百钱
if ((n + i + m == 100) && (5 * n + 3 * i + m / 3 == 100)) {
document.write('公鸡' + n + ",母鸡" + i + ',小鸡' + m)
}
}
}
}
//精简写法
for (var n = 0; n <= 20; n++) {
for (var i = 0; i <= 33; i++) {
if (5 * n + 3 * i + (100 - i - n) / 3 == 100) {
document.write('公鸡' + n + ",母鸡" + i + ',小鸡' + (100 - n - i))
}
}
}
</script>
</body>
</html>