English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

請協助以vb寫程式,謝謝!
A=ab
B=ce
C=bc
互相配對成為AB,AC,BC
如果2大項比較之下,有1個小項相同的話就合併,否則就放棄
實例:AB(比較之下,無共同者放棄),AC(因b相同,合併為abc),BC(因c相同,合併為bce)
結論為abc,bce

2006-01-25 10:19:49 · 2 個解答 · 發問者 cat 1 in 電腦與網際網路 程式設計

請問REx是什麼意思?

2006-01-25 17:51:43 · update #1

這是不是代表InStr(S2, Mid(S1, I, 1))成真時(有發現s1在s2中出現),就執行 Then以下的程式!

2006-01-26 12:04:02 · update #2

W.J.S
非常清楚,謝謝您!

2006-01-27 09:35:42 · update #3

2 個解答

Private Sub Command1_Click()
Dim A As String, B As String, C As String
A = "ab": B = "ce": C = "bc"
REx A, B: REx A, C: REx B, C
End Sub

Sub REx(ByVal S1 As String, ByVal S2 As String)
Dim I As Integer, J As Integer, B As Boolean, T As String, S As String

For I = 1 To Len(S1)
  If InStr(S2, Mid(S1, I, 1)) Then
   S2 = Replace(S2, Mid(S1, I, 1), ""): B = True
  End If
Next
If B Then
 S = S1 & S2
 For I = 1 To Len(S)
  For J = I To Len(S)
   If Mid(S, I, 1) > Mid(S, J, 1) Then
    T = Mid(S, I, 1): Mid(S, I, 1) = Mid(S, J, 1): Mid(S, J, 1) = T
   End If
  Next
 Next
 Print S
End If
End Sub

2006-01-25 23:54:48 補充:
REx只是一個任意命名的副程式名稱

2006-01-26 20:26:18 補充:
InStr(S2, Mid(S1, I, 1))>0時就表示S2裡面有Mid(S1, I, 1)這字,就利用Replace移除S2內所有的Mid(S1, I, 1),並且以B做旗標表示兩個字串內有相同的字然後排序後輸出.

2006-01-25 11:30:08 · answer #1 · answered by W.J.S. 7 · 0 0

Private Sub Command1_Click()
  A = "ab"
  B = "ce"
  C = "bc"
  ansstr = ansstr & NewStr(A, B) & ","
  ansstr = ansstr & NewStr(A, C) & ","
  ansstr = ansstr & NewStr(B, C) & ","
  ansstr = Replace(ansstr, ",,", ",")
  If Left(ansstr, 1) = "," Then ansstr = Right(ansstr, Len(ansstr) - 1)
  If Right(ansstr, 1) = "," Then ansstr = Left(ansstr, Len(ansstr) - 1)
  Print ansstr
End Sub

Function NewStr(d1, d2)
  For I = 1 To Len(d1)
    If InStr(d2, Mid(d1, I, 1)) Then
      dstr = d1 + d2
      Exit For
    End If
  Next
  NewStr = Sort(dstr)
End Function

Function Sort(d1)
  For x = 1 To Len(d1) - 1
    For y = x + 1 To Len(d1)
      If Mid(d1, x, 1) > Mid(d1, y, 1) Then
        tmp = Mid(d1, x, 1)
        Mid(d1, x, 1) = Mid(d1, y, 1)
        Mid(d1, y, 1) = tmp
      End If
    Next
  Next
  Sort = DelRepeat(d1)
End Function

Function DelRepeat(d1)
  I = 1
  While Len(d1) > I
    If Mid(d1, I, 1) = Mid(d1, I + 1, 1) Then d1 = Left(d1, I) + Right(d1, Len(d1) - I - 1)
    I = I + 1
  Wend
  DelRepeat = d1
End Function

2006-01-25 15:26:20 · answer #2 · answered by 世賢 7 · 0 0

fedest.com, questions and answers