2011-03-10 58 views
0

如何找到特定字符串的組合...如何查找字符串的排列?

ABCD - 「」,A,B,C,AB,AC,AD,BC,BD,CD,ABC,ACD,ABD,ABCD ...

C編程語言....

感謝..

+2

這是功課? – 2011-03-10 11:33:10

+2

這不是排列,這是所有可能的子集... – Vladimir 2011-03-10 11:33:51

+1

哪種編程語言? – 2011-03-10 11:34:04

回答

2

在set中插入需要的字母並調用findSubset。

Set findSubsets(Set A) 
{ 
    if A is the empty set 
      return the empty set 

    // The first element of our set is A[0] 
    // (A - A[0] is the set A without the first element) 
    Set B := findSubsets(A - A[0]) 

    // Set B is now all the subsets of A without the first element 
    // We now find all the subsets of A containing the first element by finding 
    // tacking on the first element to the sets inside B 
    Set C = {} 
    For each set D in B 
      add {A[0], D} to C 

    return B added to C 
} 
+0

這個不清楚.... – AGeek 2011-03-10 11:48:02

+2

哪部分不清楚? – SjB 2011-03-10 11:49:35

0

在Python標準庫ìtertools應該有所幫助。看看combinations()函數,也許其他人取決於你想要什麼exachly。你想重複嗎?訂單重要嗎?

+0

需要編程..理解邏輯... – AGeek 2011-03-10 11:48:18

+0

首先,你需要更準確地說你的問題。術語*排列*和*組合*定義爲不同的術語,然後,你的描述指向*子集* ... – towi 2011-03-10 11:59:43