有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少? 
要求:用C#编写输出结果,通过cmd输出,

解决方案 »

  1.   

    class Program
    {
      static void Main()
      {
        System.Console.WriteLine(@"123
    124
    132
    134
    142
    143
    213
    214
    231
    234
    241
    243
    312
    314
    321
    324
    341
    342
    412
    413
    421
    423
    431
    432");
      } 
      

  2.   


            static void Main(string[] args)
            {
                Permutate("1234", "", 1);
            }
            static void Permutate(string str, string result,int length)
            {
                if (str.Length == length)
                {
                    Console.WriteLine(result);
                }
                for (int i = 0; i < str.Length; i++)
                {
                    Permutate(str.Remove(i, 1), result + str[i],length);
                }
            }
      

  3.   

    class Program
    {
      static void Main()
      {
        for (int i = 1; i <= 4; i++)
        {
          for (int j = 1; j <= 4; j++)
          {
            for (int k = 1; k <= 4; k++)
            {
              if (!(i == j || j == k || k == i))
              {
                System.Console.WriteLine("{0}{1}{2}", i, j, k);
              }
            }
          }
        }
      }