內容 :
從機器中,不斷地出現4個英文字母的單字,現在要你抄寫下來,
倘若這個單字已經出現過,則會使用編號上的號碼直接書寫
倘若這個單字沒有出現過,則會賦予單字一個新的號碼
每組新的測資,代表不同事件,請勿將其納入新的號碼
倘若這個單字已經出現過,則會使用編號上的號碼直接書寫
倘若這個單字沒有出現過,則會賦予單字一個新的號碼
每組新的測資,代表不同事件,請勿將其納入新的號碼
輸入說明 :
每組輸入的第一行 , 有一個數字 N (1≦N≦105),接下來會有瘋狂科學家講出的N行單字,每行由小寫字母a到z所構成的4字單字.
輸出說明 :
若這個字串之前已經出現過,則輸出號碼,若沒有則輸出它將被編寫的號碼.
範例輸入 :
5
eine
isis
zwei
drei
zwei
範例輸出 :
New! 1
New! 2
New! 3
New! 4
Old! 3
Dim mycount, mystr(999), mynum As Integer
回覆刪除Dim repeat As Boolean
Private Sub Form_Load()
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As #2
Input #1, mycount
For i = 1 To mycount
Input #1, mystr(i)
For ii = 1 To i - 1
If mystr(i) = mystr(ii) Then
repeat = True
Exit For
End If
Next
If repeat <> True Then Print #2, "New! " & i
If repeat = True Then Print #2, "Old! " & ii
repeat = False
Next
Close #2
Close #1
End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim x()
Dim ans As Boolean
Open App.Path & "\in.txt" For Input As #1
Open App.Path & "\out.txt" For Output As 2
Input #1, n
ReDim x(n)
For i = 1 To n
Input #1, x(i)
ans = True
For j = 1 To i - 1
If x(i) = x(j) Then Print #2, "Old!" & j: ans = False: Exit For
Next
If ans Then Print #2, "New!" & i
Next
Close #2
Close #1
End
End Sub
Dim m()
回覆刪除Dim s As Boolean
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, x
ReDim m(x)
For i = 1 To x
Input #1, m(i)
s = False
For j = 1 To i - 1
If m(j) = m(i) Then s = True: Exit For
Next
If s = False Then
t = t + 1
Print #2, "New! " & t
Else
Print #2, "Old! " & j
End If
Next
Close
Close
End
End Sub