2011年6月9日 星期四

文字抄寫

內容 : 
從機器中,不斷地出現4個英文字母的單字,現在要你抄寫下來,
倘若這個單字已經出現過,則會使用編號上的號碼直接書寫
倘若這個單字沒有出現過,則會賦予單字一個新的號碼


每組新的測資,代表不同事件,請勿將其納入新的號碼
輸入說明 :
每組輸入的第一行 , 有一個數字 N (1≦N≦105),接下來會有瘋狂科學家講出的N行單字,每行由小寫字母a到z所構成的4字單字.

輸出說明 :
若這個字串之前已經出現過,則輸出號碼,若沒有則輸出它將被編寫的號碼.
範例輸入 :
eine 
isis 
zwei 
drei 
zwei
範例輸出 :
New! 1 
New! 2 
New! 3 
New! 4 
Old! 3

http://chscvb.blogspot.com/2010/09/blog-post_11.html

5 則留言:

  1. 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, N
    Input #1, X
    Y = Split(X)

    R = 0
    T = 0

    For i = 0 To UBound(Y)
    RE = False
    For j = 0 To (List1.ListCount - 1)
    If Y(i) = List1.List(j) Then RE = True: R = i - 1
    Next j

    If RE = False Then T = T + 1: List1.AddItem Y(i): List2.AddItem "New! " & T Else List2.AddItem "Old! " & R

    Next i

    ans = ""
    For i = 0 To (List2.ListCount - 1)
    ans = ans & List2.List(i) & " "
    Next i

    Print #2, ans

    Close #2
    Close #1

    End
    End Sub

    回覆刪除
  2. 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, Ti

    Dim ch As Boolean, tmp
    For i = 1 To Ti
    Input #1, n
    ch = False
    For k = 0 To List1.ListCount - 1
    If n = List1.List(k) Then ch = True: tmp = k
    Next
    If ch = True Then
    Print #2, " Old !" & tmp + 1
    Else
    List1.AddItem n
    Print #2, " New !" & List1.ListCount
    End If
    Next

    Close
    Close

    Next
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\out.txt" For Output As #2
    Open App.Path & "\in.txt" For Input As #1

    Input #1, n
    c = 0
    For i = 1 To n
    Input #1, x
    gg = True
    For j = 0 To List1.ListCount - 1
    If x = List1.List(j) Then Print #2, "Old! " & j + 1: gg = False: Exit For
    Next
    If gg = True Then c = c + 1: List1.AddItem x: Print #2, "New! " & c
    Next

    Close #1
    Close #2
    End
    End Sub
    ----------------------
    in.txt
    8
    eine
    isis
    zwei
    drei
    zwei
    isis
    zwei
    drei
    ----------------
    out.txt
    New! 1
    New! 2
    New! 3
    New! 4
    Old! 3
    Old! 2
    Old! 3
    Old! 4

    回覆刪除
  4. arro,緣尉好,
    兩個程式都ok。

    回覆刪除