本帖最后由 _ddqs. 于 2010-12-18 16:32 编辑 ;多少钱可以买100只鸡
For $x = 1 To 100
$ret = _buy($x)
If $ret <> "" Then
ConsoleWrite(@LF & @LF & "花了" & $x & "文可以买100只鸡" & @LF & "--------------------------" & @LF)
ConsoleWrite($ret)
ConsoleWrite("--------------------------" & @LF & @LF & @LF)
EndIf
Next
Func _buy($money)
Local $ret = ""
For $i = 1 To $money / 3
For $j = 1 To ($money - $i) / 5
If (($money - $i) - $j * 5) / 3 + $j + $i * 3 = 100 And _
Mod(($money - $i) - $j * 5, 3) = 0 And _
(($money - $i) - $j * 5) / 3 <> 0 _
Then
$ret &= @LF & "公鸡" & $j & "母鸡" & (($money - $i) - $j * 5) / 3 & "鸡仔" & $i * 3 & @LF
$ret &= "公鸡" & $j*5 &" 文 "& "母鸡" & ((($money - $i) - $j * 5) / 3)*3 &" 文 "& "鸡仔" & $i * 3 / 3 &" 文 "& @LF
$ret &= "共" & ($j*5) + (((($money - $i) - $j * 5) / 3)*3) + ($i * 3 / 3) &" 文 "& @LF
EndIf
Next
Next
Return $ret
EndFunc ;==>_buy
;多少钱可以买100只鸡
For $x = 1 To 100
$ret = _buy($x)
If $ret <> "" Then
ConsoleWrite(@LF & @LF & "花了" & $x & "文可以买100只鸡" & @LF & "--------------------------" & @LF)
ConsoleWrite($ret)
ConsoleWrite("--------------------------" & @LF & @LF & @LF)
EndIf
Next
Func _buy($money)
Local $ret = ""
For $i = 1 To $money / 3 ;女士优先(虽然与BB的循环次数一样,但可最大限度的降低内循环的值,使循环次数更少,并取得的数据会更多)
For $j = 1 To ($money - $i * 3) / 5 ;男士追上
;最后才有BB
If (($money - $i * 3) - ($j * 5)) <> 0 And $j + $i + (($money - ($i * 3) - ($j * 5)) * 3) = 100 Then ;计算余额非 0 并 总只数为 100.
$ret &= @LF & "公鸡" & $j & "只,母鸡" & $i & "只,鸡仔" & (($money - $i * 3) - ($j * 5)) * 3 &"只"& @LF
$ret &= "公鸡" & $j * 5 & "文," & "母鸡" & $i * 3 & "文," & "鸡仔" & (($money - $i * 3) - ($j * 5)) & "文" & @LF
$ret &= "共" & ($j * 5) + ($i * 3) + (($money - $i * 3) - ($j * 5)) & "文("& $j + $i + (($money - ($i * 3) - ($j * 5)) * 3) &"只)"& @LF
EndIf
Next
Next
Return $ret
EndFunc ;==>_buy
|