Dim x As String Dim ans(4) As String Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x ans(0) = Len(x) For i = 1 To 3 For j = 1 To Len(x) y = Mid(x, j, 1) If i = 1 Then If y = "4" Then ans(i) = ans(i) + "4*號" Else ans(i) = ans(i) + y End If End If If i = 2 Then If y = "3" Then ans(i) = ans(i) + "3+號" Else ans(i) = ans(i) + y End If End If If i = 3 Then If y = "5" Then ans(i) = ans(i) + "5?號" Else ans(i) = ans(i) + y End If End If Next j Next i For i = 0 To 3 Print #2, i + 1 & ":" & ans(i) Next i
Dim x As String Dim ans(4) As String Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 Input #1, x ans(0) = Len(x) ans(1) = Replace(x, "4", "4*號") ans(2) = Replace(x, "3", "3+號") ans(3) = Replace(x, "5", "5?號") For i = 0 To 3 Print #2, i + 1 & ":" & ans(i) Next i Close #2 Close #1 End Sub 用了Replace變的好快...
Dim ans1, ans2, ans3 As String Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x n = Len(x) For i = 1 To n a = Mid(x, i, 1) If a = "4" Then ans1 = ans1 & "4*號" Else ans1 = ans1 & a End If Next i For i = 1 To n a = Mid(x, i, 1) If a = "3" Then ans2 = ans2 & "3+號" Else ans2 = ans2 & a End If Next i For i = 1 To n a = Mid(x, i, 1) If a = "5" Then ans3 = ans3 & "5?號" Else ans = ans3 & a End If Next i Print "(1)" & n Print "(2)" & ans1 Print "(3)" & ans2 Print "(4)" & ans3 Close #1 Close #2 End Sub 想不到還有這個函數 以後來試試看@@
replace 字串中只要出現的每一個字都能替代 Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Line Input #1, x Close #1 Print #2, Len(x) Print #2, Replace(x, "4", "4*號") Print #2, Replace(x, "3", "3+號") Print #2, Replace(x, "5", "5?號") Close #2 End Sub
Dim x As String Dim ans(4) As String Private Sub Form_Load() Open App.Path & "\in.txt" For Input As #1 Input #1, x ans(1) = Len(x) strAns = x For i = 1 To Len(x) strX = Mid(x, i, 1) Select Case strX Case Is = "4" ans(2) = Mid(x, 1, i - 1) & "4*號" & Mid(x, i + 1, Len(x)) Case Is = "3" ans(3) = Mid(x, 1, i - 1) & "3+號" & Mid(x, i + 1, Len(x)) Case Is = "5" ans(4) = Mid(x, 1, i - 1) & "5?號" & Mid(x, i + 1, Len(x)) End Select Next i Close #1 Open App.Path & "\out.txt" For Output As #1 For i = 1 To 4 Print #1, ans(i) Next i Close #1 End Sub
Public Sub Form_Load() Me.Hide Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Line Input #1, x Print #2, Len(x) Print #2, Replace(x, "4", "4*號") Print #2, Replace(x, "3", "3+號") Print #2, Replace(x, "5", "5?號") Close #2 Close #1 End End Sub
Dim x As String
回覆刪除Dim ans(4) As String
Private Sub Form_Load()
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x
ans(0) = Len(x)
For i = 1 To 3
For j = 1 To Len(x)
y = Mid(x, j, 1)
If i = 1 Then
If y = "4" Then
ans(i) = ans(i) + "4*號"
Else
ans(i) = ans(i) + y
End If
End If
If i = 2 Then
If y = "3" Then
ans(i) = ans(i) + "3+號"
Else
ans(i) = ans(i) + y
End If
End If
If i = 3 Then
If y = "5" Then
ans(i) = ans(i) + "5?號"
Else
ans(i) = ans(i) + y
End If
End If
Next j
Next i
For i = 0 To 3
Print #2, i + 1 & ":" & ans(i)
Next i
Close #2
Close #1
End Sub
Dim x As String
回覆刪除Dim ans(4) As String
Private Sub Form_Load()
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
Input #1, x
ans(0) = Len(x)
ans(1) = Replace(x, "4", "4*號")
ans(2) = Replace(x, "3", "3+號")
ans(3) = Replace(x, "5", "5?號")
For i = 0 To 3
Print #2, i + 1 & ":" & ans(i)
Next i
Close #2
Close #1
End Sub
用了Replace變的好快...
Dim ans1, ans2, ans3 As String
回覆刪除Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
n = Len(x)
For i = 1 To n
a = Mid(x, i, 1)
If a = "4" Then
ans1 = ans1 & "4*號"
Else
ans1 = ans1 & a
End If
Next i
For i = 1 To n
a = Mid(x, i, 1)
If a = "3" Then
ans2 = ans2 & "3+號"
Else
ans2 = ans2 & a
End If
Next i
For i = 1 To n
a = Mid(x, i, 1)
If a = "5" Then
ans3 = ans3 & "5?號"
Else
ans = ans3 & a
End If
Next i
Print "(1)" & n
Print "(2)" & ans1
Print "(3)" & ans2
Print "(4)" & ans3
Close #1
Close #2
End Sub
想不到還有這個函數 以後來試試看@@
高仔好,
回覆刪除你的程式和你寫的輸出範例,不同哦。
有沒有()呢?
還有,你怎麼會用到雙迴圈呢?這不是單迴圈,就能解決的嗎?
阿瑋好,
你用的是單迴圈,可是,你不覺得這幾個單迴圈「超類似」嗎?
應該也是用成一個迴圈就行了的吧?
replace這個函數,設定是如何呢? 只會找出第一個來更換,還是,「每一個」呢?
replace 字串中只要出現的每一個字都能替代
回覆刪除Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Line Input #1, x
Close #1
Print #2, Len(x)
Print #2, Replace(x, "4", "4*號")
Print #2, Replace(x, "3", "3+號")
Print #2, Replace(x, "5", "5?號")
Close #2
End Sub
果然百練成鋼,這該是最精簡版了吧。無趣的可怕。
回覆刪除ㄚ阿...那個() 是我程式做一做忘了加上去
回覆刪除粗心= ="
Dim x As String
回覆刪除Dim ans(4) As String
Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Input #1, x
ans(1) = Len(x)
strAns = x
For i = 1 To Len(x)
strX = Mid(x, i, 1)
Select Case strX
Case Is = "4"
ans(2) = Mid(x, 1, i - 1) & "4*號" & Mid(x, i + 1, Len(x))
Case Is = "3"
ans(3) = Mid(x, 1, i - 1) & "3+號" & Mid(x, i + 1, Len(x))
Case Is = "5"
ans(4) = Mid(x, 1, i - 1) & "5?號" & Mid(x, i + 1, Len(x))
End Select
Next i
Close #1
Open App.Path & "\out.txt" For Output As #1
For i = 1 To 4
Print #1, ans(i)
Next i
Close #1
End Sub
小白好,
回覆刪除這題解得不錯哦。沒有用上面其它人的方式,想想自己的不同,果然能表現出一點兒企圖心,很好。再加油。
Public Sub Form_Load()
回覆刪除Me.Hide
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Line Input #1, x
Print #2, Len(x)
Print #2, Replace(x, "4", "4*號")
Print #2, Replace(x, "3", "3+號")
Print #2, Replace(x, "5", "5?號")
Close #2
Close #1
End
End Sub
2M12