如何找到特定字符串的组合......
ABCD - “”,A,B,C,AB,AC,AD,BC,BD,CD,ABC,ACD,ABD,ABCD,......
C编程语言....
感谢..
答案 0 :(得分: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
}
答案 1 :(得分:0)
在python中,标准库ìtertools应该有所帮助。看看combinations()
功能,也许还有其他功能,具体取决于您想要的 exacly 。你想允许重复吗?订单重要吗?