回覆列表
  • 1 # 手機使用者87197936035

    static void Main(string[] args)

    {

    string s = Console.ReadLine();//多個數字之間用半形逗號隔開

    string[] sarr = s.Split(new char[] { "," });//分割字串,獲得字串陣列

    int[] arr = new int[sarr.Length];//定義新的整型陣列,放原始排列順序

    int[] newarr = new int[sarr.Length];//定義新的整型陣列,用於氣泡排序

    for (int sa = 0; sa < sarr.Length; sa++) //給新定義的2個數組賦值

    {

    arr[sa] = Convert.ToInt32(sarr[sa]);

    newarr[sa] = Convert.ToInt32(sarr[sa]);

    }

    int k = 0;//中間變數,用於氣泡排序

    for (int i = 0; i < newarr.Length; i++)//氣泡排序

    {

    for (int j = i + 1; j < newarr.Length; j++)

    {

    if (newarr[i] < newarr[j])

    {

    k = newarr[i];

    newarr[i] = newarr[j];

    newarr[j] = k;

    }

    }

    }

    Console.Write("原始排列:");

    foreach (int a in arr)

    {

    Console.Write(a + ",");

    }

    Console.WriteLine("");

    Console.Write("新的排列:");

    foreach (int na in newarr)

    {

    Console.Write(na + ",");

    }

    Console.WriteLine("");

    Console.ReadKey();

    }

  • 中秋節和大豐收的關聯?
  • 簡譜怎麼配和絃?