int a//大鱼的数量
int b//中鱼的数量
int c//小鱼的数量
for(int i = 0i<=20i++){
a=i
for(int j = 0j<=33j++){
b=j
for(int k = 0k<=500k++){
c=k
if(a*5+b*3+c*0.2==100){
System.out.print("大鱼:"+a+"\t")
System.out.print("中鱼:"+b+"\t")
System.out.println("小鱼:"+c+"\t")
}
}
}
}
}
有100人民币要买100串烧烤,鱼3元,排骨2元,土豆片0.5元问能买鱼,排骨,土豆片各多少串?<br/>
请编写出程序
<?php
for($y=1$y<=33$y++)
{
for($p=1$p<=50$p++)
{
$t=100-$p-$y
$money=$y*3+$p*2+$t*0.5
$sum=$y+$p+$t
if($money==100)
{
echo "<br/>"
echo "Money:".$money
echo "\tSum:".$sum
echo "\t鱼:".$y
echo "\t排骨:".$p
echo "\t土豆片:".$t
}
}
}
?>
Money:100 Sum:100 鱼:2 排骨:30 土豆片:68
Money:100 Sum:100 鱼:5 排骨:25 土豆片:70
Money:100 Sum:100 鱼:8 排骨:20 土豆片:72
Money:100 Sum:100 鱼:11 排骨:15 土豆片:74
Money:100 Sum:100 鱼:14 排骨:10 土豆片:76
Money:100 Sum:100 鱼:17 排骨:5 土豆片:78
public class Fishman {public static void main(String[] args) {
calcFish()
}
private static void calcFish() {
int total = 8//至少有8条=邻居的海伦3条+又吃了一条 + 剩下4条
int left = 0
do {
int sold = total / 2//第一次卖掉一般剩下的
int firstLeft = sold - 3//送掉邻居海伦剩下的
if(firstLeft % 3 == 0){
left = firstLeft/3 - 1// 三分之一里面-吃掉的一条
if(left == 4 ){
System.out.println("total: " + total + " fish")
}
}
total += 2//刚开始能平均2份,因此鱼数必定是偶数,步长为2
} while (left != 4)
}
}
一共36条