猿问

与路径的排列组合?

我有输入就像“dir1/dir2/Demo.txt”

结合我想要的输出

  • “dir1/dir2/Demo.txt”

  • “dir1/dir2/DEMO.txt”

  • "dir1/DIR2/Demo.txt"

  • “dir1/DIR2/DEMO.txt”

  • "DIR1/dir2/Demo.txt"

  • "DIR1/dir2/DEMO.txt"

  • “DIR1/DIR2/Demo.txt”

  • "DIR1/DIR2/DEMO.txt"

据我所知,我编写的代码如下

  var s = "dir1/dir2/Demo.txt";

   List<string> listPermutations = new List<string>();

   string[] array = s.Split('/');

   int iterations = (1 << array.Length) -1;

   for( int i = 0; i <= iterations; i++ )

   {

       for( int j = 0; j < array.Length; j++ )

            array[j] = (i & (1<<j)) != 0

                ? array[j].ToUpper()

                : array[j];

       listPermutations.Add(string.Join("/",array ));

   }


斯蒂芬大帝
浏览 152回答 1
1回答
随时随地看视频慕课网APP
我要回答