zoukankan      html  css  js  c++  java
  • C#求所有可能的排列组合

    static System.Collections.Specialized.StringCollection MakeStrings(string[] characters, int finalStringLength)
    {
        int finalLength = finalStringLength; // The length of the final strings.
        System.Collections.Specialized.StringCollection existingStrings;
        System.Collections.Specialized.StringCollection newStrings =
            new System.Collections.Specialized.StringCollection(); // Start with the all one-letter combinations.
     
        newStrings.AddRange(characters);
     
        for (int len = 2; len <= finalLength; len++)
        {
            // Start a new collection of strings based on the existing strings.
            existingStrings = newStrings;
            newStrings = new System.Collections.Specialized.StringCollection();
     
            // Concatenate every string of length (len-1)...
            foreach (string str in existingStrings)
            {
                // ...with every character...
                foreach (string ch in characters)
                {
                    // ...to create every possible string of length len.
                    newStrings.Add(str + ch);
                }
            }
        }
        return newStrings;
    }
  • 相关阅读:
    XML 编码
    XML CDATA
    XML 命名空间
    XML 解析器
    XML XMLHttpRequest 对象
    XML 和CSS
    XML 验证
    XML 属性
    XML 元素
    XML 语法规则
  • 原文地址:https://www.cnblogs.com/rinack/p/4135499.html
Copyright © 2011-2022 走看看