Dim x, y, z, k, num, Money As Integer Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, num Do For x = 0 To 1 If x * 50 > num Then Call printt("50*" & x & "=" & x * 50 & "找" & ((x * 50) - num) & "元"): Exit For For y = 0 To 3 If x * 50 + y * 10 > num Then Call printt("10*" & y & "+50*" & x & "=" & x * 50 + y * 10 & " " & "找" & ((x * 50 + y * 10) - num) & "元"): Exit For For z = 0 To 5 If x * 50 + y * 10 + z * 5 > num Then Call printt("5*" & z & "+10*" & y & "+50*" & x & "=" & x * 50 + y * 10 + z * 5 & " " & "找" & ((x * 50 + y * 10 + z * 5) - num) & "元"): Exit For For k = 0 To 25 Money = (x * 50) + (y * 10) + (z * 5) + (k * 1) If Money >= num And Money <= 50 Then Call printt("1*" & k & "+5*" & z & "+10*" & y & "+50*" & x & "=" & Money & " " & " " & "找" & (Money - num) & "元"): Exit For Next Next Next Next Loop Until EOF(1) Close #2 Close #1 End End Sub
Public Sub printt(strr As String) strr = Replace(strr, "1*0+", "") strr = Replace(strr, "5*0+", "") strr = Replace(strr, "10*0+", "") strr = Replace(strr, "+50*0", "") Print #2, strr End Sub
Private Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 a = Split("1,5,10,50", ",") Input #1, n Print #2, "1*" & n & "=" & n & " 找0元" For i = 1 To 3 r = Val(n) \ Val(a(i)) For j = 1 To r + 1 If Val(a(i)) * j < Val(n) Then ans = Val(n) - Val(a(i)) * j If ans Mod Val(a(i - 1)) = 0 Then Print #2, a(i - 1) & "*" & ans \ Val(a(i - 1)) & "+" & a(i) & "*" & j & "=" & Val(n) & " 找0元" Else Print #2, a(i) & "*" & j & "=" & Val(a(i)) * j & " 找" & Val(a(i)) * j - Val(n) & "元" End If Next j Next i Close #2 Close #1 End End Sub
Dim x, y, z, k, num, Money As Integer
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, num
Do
For x = 0 To 1
If x * 50 > num Then Call printt("50*" & x & "=" & x * 50 & "找" & ((x * 50) - num) & "元"): Exit For
For y = 0 To 3
If x * 50 + y * 10 > num Then Call printt("10*" & y & "+50*" & x & "=" & x * 50 + y * 10 & " " & "找" & ((x * 50 + y * 10) - num) & "元"): Exit For
For z = 0 To 5
If x * 50 + y * 10 + z * 5 > num Then Call printt("5*" & z & "+10*" & y & "+50*" & x & "=" & x * 50 + y * 10 + z * 5 & " " & "找" & ((x * 50 + y * 10 + z * 5) - num) & "元"): Exit For
For k = 0 To 25
Money = (x * 50) + (y * 10) + (z * 5) + (k * 1)
If Money >= num And Money <= 50 Then Call printt("1*" & k & "+5*" & z & "+10*" & y & "+50*" & x & "=" & Money & " " & " " & "找" & (Money - num) & "元"): Exit For
Next
Next
Next
Next
Loop Until EOF(1)
Close #2
Close #1
End
End Sub
Public Sub printt(strr As String)
strr = Replace(strr, "1*0+", "")
strr = Replace(strr, "5*0+", "")
strr = Replace(strr, "10*0+", "")
strr = Replace(strr, "+50*0", "")
Print #2, strr
End Sub
回覆刪除Private Sub Form_Load()
Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
a = Split("1,5,10,50", ",")
Input #1, n
Print #2, "1*" & n & "=" & n & " 找0元"
For i = 1 To 3
r = Val(n) \ Val(a(i))
For j = 1 To r + 1
If Val(a(i)) * j < Val(n) Then
ans = Val(n) - Val(a(i)) * j
If ans Mod Val(a(i - 1)) = 0 Then Print #2, a(i - 1) & "*" & ans \ Val(a(i - 1)) & "+" & a(i) & "*" & j & "=" & Val(n) & " 找0元"
Else
Print #2, a(i) & "*" & j & "=" & Val(a(i)) * j & " 找" & Val(a(i)) * j - Val(n) & "元"
End If
Next j
Next i
Close #2
Close #1
End
End Sub