2011年6月9日 星期四
竊車問題 (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
訂閱:
張貼留言 (Atom)
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, a, b
For i = 1 To a
Input #1, n
List1.AddItem n
Next
For i = 1 To b
Input #1, n
List2.AddItem n
Next
'///////////////
For i = 0 To List1.ListCount - 1
For ii = 0 To List2.ListCount - 1
If Left(List1.List(i), 6) = Left(List2.List(ii), 6) Then List3.AddItem List2.List(ii)
Next
Next
'///////////////
For i = 0 To List3.ListCount - 1
Print #2, List3.List(i)
Next
Close #2
Close #1
End
End Sub
//////////////
輸入:
3 4
GTX460
KTR332
MVP945
VIP543 BLACK Someone
GTX460 PINK M.D.
KTR332 WHITE Dr.X
MVP945 N/A Nobody
輸出:
GTX460 PINK M.D.
KTR332 WHITE Dr.X
MVP945 N/A Nobody
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
Line Input #1, X
List1.AddItem X
Next i
For i = 1 To N2
Line Input #1, Y
List2.AddItem Y
Next i
For i = 0 To (List1.ListCount - 1)
For j = 0 To (List2.ListCount - 1)
If List1.List(i) = Left(List2.List(j), 6) Then List3.AddItem List2.List(j)
Next j
Next i
For i = 0 To (List3.ListCount - 1)
Print #2, List3.List(i)
Next i
Close #2
Close #1
End
End Sub
----
輸入:
3 4
GTX460
KTR332
MVP945
VIP543 BLACK Someone
GTX460 PINK M.D.
KTR332 WHITE Dr.X
MVP945 N/A Nobody
輸出:
GTX460 PINK M.D.
KTR332 WHITE Dr.X
MVP945 N/A Nobody
Dim sus(20), lost(100)
回覆刪除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, m
For i = 0 To n - 1
Input #1, sus(i)
Next
For i = 0 To m - 1
Line Input #1, lost(i)
Next
For i = 0 To n - 1
For j = 0 To m - 1
If sus(i) = Left(lost(j), 6) Then List1.AddItem lost(j)
Next
Next
For i = 0 To List1.ListCount - 1
Print #2, List1.List(i)
Next
Close #1
Close #2
End
End Sub
這題三個的程式都ok。
回覆刪除只有arro的輸入,是不是也用line input比較安全?