Private Sub Form_Load() Open App.Path & "in.txt" For Input As #1 Input #1, x Close #1 L = Left(x, 3) For I = 0 To 7 a = Mid(x, Len(x) - I, 1) ans = True For J = 1 To 3 b = Mid(L, J, 1) If a = b Then ans = False Next J If ans Then R = a + R Next I out = L & R Open App.Path & "out.txt" For Output As #2 Print #2, x Close #2 End Sub
Private Sub Form_Load() Dim ansl(3) As String Open App.Path & "\in.txt" For Input As #1 Open App.Path & "\out.txt" For Output As #2 Input #1, x Close #1 For i = 1 To 3 ansl(i) = Mid(x, i, 1) Print #2, ansl(i); Next i x = Right(x, Len(x) - 9) For i = 1 To 8 ha: For j = 1 To 3 If Mid(x, i, 1) = ansl(j) Then i = i + 1 GoTo ha ElseIf j = 3 Then Print #2, Mid(x, i, 1); End If Next j Next i Close #2 End Sub
Dim ansSt As String Dim qSt(2) As String Dim st1(8) As String Dim st2(8) As String Dim nexSt(5) As String Private Sub Form_Load() Open App.Path & "/in.txt" For Input As #1 Input #1, x q = Split(x, " ") qSt(1) = q(0) qSt(2) = q(1) For i = 1 To 8 st1(i) = Mid(qSt(1), i, 1) st2(i) = Mid(qSt(2), i, 1) Next i a = 1 For i = 1 To 8 If st2(i) <> st1(1) And st2(i) <> st1(2) And st2(i) <> st1(3) Then nexSt(a) = st2(i) a = a + 1 End If Next i ansSt = Mid(qSt(1), 1, 3) For i = 1 To 5 ansSt = ansSt & nexSt(i) Next i Close #1 Open App.Path & "/out.txt" For Output As #2 Print #2, ansSt Close #2 End Sub
Private Sub Form_Load()
回覆刪除Open App.Path & "in.txt" For Input As #1
Input #1, x
Close #1
L = Left(x, 3)
For I = 0 To 7
a = Mid(x, Len(x) - I, 1)
ans = True
For J = 1 To 3
b = Mid(L, J, 1)
If a = b Then ans = False
Next J
If ans Then R = a + R
Next I
out = L & R
Open App.Path & "out.txt" For Output As #2
Print #2, x
Close #2
End Sub
作者已經移除這則留言。
回覆刪除Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As #1
Input #1, n
Close #1
Open App.Path & "\out.txt" For Output As #2
txt1 = Left(n, 3)
txt2 = Right(n, 8)
For i = 1 To 8
ans = True
For j = 1 To 3
a = Mid(txt2, i, 1)
b = Mid(txt1, j, 1)
If a = b Then ans = False
Next j
If ans Then txt = txt & a
Next i
txt = txt1 & txt
Print #2, txt
Close #2
End Sub
Private Sub Form_Load()
回覆刪除Dim ansl(3) As String
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, x
Close #1
For i = 1 To 3
ansl(i) = Mid(x, i, 1)
Print #2, ansl(i);
Next i
x = Right(x, Len(x) - 9)
For i = 1 To 8
ha:
For j = 1 To 3
If Mid(x, i, 1) = ansl(j) Then
i = i + 1
GoTo ha
ElseIf j = 3 Then
Print #2, Mid(x, i, 1);
End If
Next j
Next i
Close #2
End Sub
高仔好,
回覆刪除1. a=mid(x,len(x)-i,1)
這行取到的字,不是從後頭來的嗎?所以你接字串時用了
R=a+R
把它接在前面。可以是可以啦,似乎考慮的方向怪怪的。
這樣的話,要記得多看幾次結果哦。
2. 這樣的話,以後你們post上來的時候,請也將你們的in.txt和out.txt給post上來吧。
尤其可能的話,記得用些特殊的in.txt來想想一些「邊界」「極端」的可能輸入。
阿瑋好,
1.你在雙迴圈中,
a=mid(txt2.i,1)
這行放在內圈白白多執行了16次。應該放在外圈就好了。
Y揚好,
1. x=right(x,len(x)-9)
->
x = right(x,8)
反正你是要右邊的那8個字,不是嗎。
2. i=i+1
goto ha
->
exit for
跳出一層迴圈即可。
**
以後就試著也將各種可能的in.txt和你們程式執行的out.txt給post上來。
要小心,題目給的例子,只是可能輸入的一種而已,要多想想還有那些可能的輸入。
對耶=ˋ= 我原本有想到。以為 用1次怕跳出2個迴圈
回覆刪除所以就用GOTO了
Dim ansSt As String
回覆刪除Dim qSt(2) As String
Dim st1(8) As String
Dim st2(8) As String
Dim nexSt(5) As String
Private Sub Form_Load()
Open App.Path & "/in.txt" For Input As #1
Input #1, x
q = Split(x, " ")
qSt(1) = q(0)
qSt(2) = q(1)
For i = 1 To 8
st1(i) = Mid(qSt(1), i, 1)
st2(i) = Mid(qSt(2), i, 1)
Next i
a = 1
For i = 1 To 8
If st2(i) <> st1(1) And st2(i) <> st1(2) And st2(i) <> st1(3) Then
nexSt(a) = st2(i)
a = a + 1
End If
Next i
ansSt = Mid(qSt(1), 1, 3)
For i = 1 To 5
ansSt = ansSt & nexSt(i)
Next i
Close #1
Open App.Path & "/out.txt" For Output As #2
Print #2, ansSt
Close #2
End Sub
小白好,
回覆刪除前進中,不錯。
這題用得有些土法練鋼,還行。
還有可以用replace()的方式,可以更簡單些。