字符串穷举

偷懒,c#代码:

class Program
    {
        static char[] c = new char[6];
        static int l;
        static void Main(string[] args)
        {
            string s;
            s = Console.ReadLine();
            l = s.Length;
            qiongju(0, s);
            Console.ReadKey();
        }
        static void qiongju(int p,string s)
        {
            if (p == l)
            {
                for (int i = 0; i < l; i++)
                {
                    Console.Write(c[i]);
                }
                Console.WriteLine();
            }
            else
            {
                for (int i = 0; i < s.Length; i++)
                {
                    c[p] = s[i];
                    qiongju(p + 1, s.Remove(i, 1));
                }
            }
        }
    }

运行结果:

原文地址:https://www.cnblogs.com/wanjinliu/p/13294367.html