2012年11月20日 星期二

竊車問題 (Lostcar)

一位警察發現了一些可疑的機車,為了查明這些可疑的機車是否為失竊機車,他需將這些機車的車號與警政署的失竊機車檔案比對。請寫一程式來幫助這位警察找出哪些是失竊的機車。


條件限制
警察發現的可疑機車不超過20輛。 
警政署的失竊機車檔案中最多為100輛機車資料。 


輸入檔格式
第一行有兩個整數n和m,中間以一個空白分開。n為發現的可疑機車數目,m為失竊機車檔案中機車的數目。接下來的n行,每行有一可疑機車的車號,車號以六個字元表示。再接下來的m行,則為失竊機車資料,每行有三項資料,各項資料間以一個空白隔開;第一項資料(欄位1~6)為機車車號,第二項(欄位8~13)為該車外觀顏色,第三項(欄位15~20)為該車車主姓名。


輸出檔格式 
請依車牌的順序(英文字母由A~Z)依序印出找到的失竊機車資料。


輸入範例
4 6
PIG222
WIN555
SAD321
JOY866
DOG999 RED CHANG 
JOY355 BLUE LEE 
SAD321 YELLOW WANG 
FOX555 WHITE WU 
WIN555 BROWN HO 
PIG222 BLACK LIN 


輸出範例


PIG222 BLACK LIN 
SAD321 YELLOW WANG
WIN555 BROWN HO 

3 則留言:

  1. Dim maybe(), stolen() As String
    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, temp1, temp2
    ReDim maybe(temp1)
    ReDim stolen(temp2)
    For i = 1 To temp1
    Input #1, maybe(i)
    Next
    For ii = 1 To temp2
    Input #1, stolen(ii)
    Next
    For iii = 1 To temp1
    For iiii = 1 To temp2
    If InStr(stolen(iiii), maybe(iii)) <> 0 Then List1.AddItem stolen(iiii)
    Next
    Next
    For iiiii = 0 To List1.ListCount - 1
    Print #2, List1.List(iiiii)
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Dim x(), y()
    Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, a, b
    ReDim x(a)
    ReDim y(b)
    For i = 0 To a - 1
    Input #1, x(i)
    Next
    For k = 0 To b - 1
    Input #1, y(k)
    Next
    For q = 0 To a - 1
    For p = 0 To b - 1
    If InStr(y(p), x(q)) > 0 Then List1.AddItem y(p)
    Next
    Next
    For z = 0 To List1.ListCount - 1
    Print #2, List1.List(z)
    Next
    Close
    Close
    End
    End Sub

    回覆刪除
  3. 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, n1, n2
    For i = 1 To n1
    Input #1, a
    List1.AddItem a
    Next
    For i = 1 To n2
    Input #1, a
    List2.AddItem a
    Next
    For i = 0 To List1.ListCount - 1
    a = List1.List(i)
    For j = 0 To List2.ListCount - 1
    If a = Left(List2.List(j), 6) Then List3.AddItem (List2.List(j))
    Next
    Next
    For i = 0 To List3.ListCount - 1
    Print #2, List3.List(i)
    Next
    Close #2
    Close #1
    End
    End Sub

    回覆刪除