求助编写找相同程序,可看示例说明
这是找相同程序示例说明给出的数据如下:
1号Data 2,3,4,9,10,11,15,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
2号Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
3号Data 4,5,7,8,9,10,13,14,15,16,17,18,19,20,22,24,25,26,27,28,29,0,0,0,0,0,0,0,0,0,0,0,0
4号Data 2,3,4,9,10,11,15,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
5号Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
6号Data 2,3,4,9,10,11,15,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
7号Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
8号Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
9号Data 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,30,31,32,33,0,0,0,0
10号Data 4,5,7,8,9,10,13,14,15,16,17,18,19,20,22,24,25,26,27,28,29,0,0,0,0,0,0,0,0,0,0,0,0
找相同方法分析(算法分析):
第一种输出结果:
1、为便于分析我把每组编上号,如上.
2、开始找相同,首先第一行和第二行(1号和2号)进行比较,1行和2行不相同;第1行再和第3行比较,也不相同;再进行第1行和第4行比较,这两行相同,随后就输出其中的一行。当第一行和下面的所有行都比较完之后;在进行第2行和第3行比较,以此类推。这种比较输出的结果如下:
第一种输出结果:
Data 2,3,4,9,10,11,15,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 2,3,4,9,10,11,15,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 4,5,7,8,9,10,13,14,15,16,17,18,19,20,22,24,25,26,27,28,29,0,0,0,0,0,0,0,0,0,0,0,0
第二种输出结果:
比较的方法和第一种方法一致,只是输出形式不同,比较时无论有多少行相同,把相同的只输出一组,没有相同的行就不要输出了,这种情况输出结果是:
Data 2,3,4,9,10,11,15,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 5,6,7,9,10,13,18,19,20,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
Data 4,5,7,8,9,10,13,14,15,16,17,18,19,20,22,24,25,26,27,28,29,0,0,0,0,0,0,0,0,0,0,0,0
要求及说明:
1、在输出结果中在前面要含有DATA。
2、每行个数33个数,不够的用“0”补齐;输出时每行排列顺序是从小到大。
3、关键是程序输入的两部分数据不止前面示例那样多,每部分可能有百组、上千组或者上万组。4、每行输出后面要显示出该行含有多少个数字。比如n=数字。
5、要有数据的输入和输出,并且能保存输出的数据。
6、在数据输出时能有选择性的输出。比如在找相同后输出时,只输出含有n=16,或n从16到18之间的行。当不输入约束条件时,就把找到的有相同的数全部输出。
7、这两种输出结果,要用两个程序来完成,也就是要编2个程序。
--------------------编程问答-------------------- 请问一下,输入数据是数据串,如上面所示:
"Data 2,3,4,9,10,11,15,19,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0"
还是
"Data 2,3,4,9,10,11,15,19"
还是数组(按大小已排序)
dim Data(7) as long
Data(0)=2
Data(1)=3
......
还是数组(没有排序)
dim Data(7) as long
Data(0)=9
Data(1)=2
Data(2)=11
......
--------------------编程问答--------------------
--------------------编程问答-------------------- 有这么麻烦吗?
Dim Data() As String
Dim ArrFlag() As Single
Private Sub Command1_Click()
Open "F:\data.txt" For Input As #1
Dim Z As String
Dim Count As Single
Count = 0
Do Until EOF(1)
Line Input #1, Z
ReDim Preserve Data(Count) As String
Data(Count) = Z
Count = Count + 1
Loop
Close #1
''以上是取出数据
Analyse (Data)
Dim Arr() As String
Arr = GetData_1
For i = 0 To UBound(Arr)
Print Arr(i)
Next
Arr = GetData_2
For i = 0 To UBound(Arr)
Print Arr(i)
Next
End Sub
Private Sub Analyse(ByVal Data) '数据分析
ReDim ArrFlag(UBound(Data)) As Single
Dim i As Single
For i = 0 To UBound(Data) - 1
If ArrFlag(i) = 0 Then
For j = i + 1 To UBound(Data)
If ArrFlag(j) = 0 Then
If Data(i) = Data(j) Then
ArrFlag(i) = 1
ArrFlag(j) = 2
End If
End If
Next
End If
Next
End Sub
Private Function GetData_1() As String() '按第一种方式输出,注意结果没有排序
Dim Count As Single
Dim m_Data() As String
Count = 0
For i = 0 To UBound(ArrFlag)
If ArrFlag(i) = 2 Then
ReDim Preserve m_Data(Count) As String
m_Data(Count) = Data(i)
Count = Count + 1
End If
Next
GetData_1 = m_Data
End Function
Private Function GetData_2() As String() '按第二种方式输出
Dim Count As Single
Dim m_Data() As String
Count = 0
For i = 0 To UBound(ArrFlag)
If ArrFlag(i) = 1 Then
ReDim Preserve m_Data(Count) As String
m_Data(Count) = Data(i)
Count = Count + 1
End If
Next
GetData_2 = m_Data
End Function
直接丢数据库里,一个SQL语句不就查询出来了。 --------------------编程问答--------------------
弄个数据库,不是更麻烦嘛 --------------------编程问答-------------------- 用字典会好些吧:
Dim dic As Object--------------------编程问答-------------------- 易做图????? --------------------编程问答--------------------
Private Sub Command1_Click()
Set dic = CreateObject("scripting.dictionary")
Dim s() As String, i As Long
Open "F:\data.txt" For Input As #1
s = Split(StrConv(InputB(LOF(1), 1), vbUnicode), vbCrLf)
Close #1
For i = 0 To UBound(s)
dic(s(i)) = dic(s(i)) + 1
Next
MsgBox data(1)
MsgBox data(0)
End Sub
Function data(ByVal outtype As Byte) As String
Dim i As Long
For Each d In dic.keys
If dic(d) > 1 Then
For i = 1 To dic(d) ^ outtype
data = data & d & vbCrLf
Next
End If
Next
End Function
逗号分割的文本文件是可以直接当成数据表进行数据库查询的,不需要额外的数据库
补充:VB , 基础类