The user enters a list of integers, separated by spaces, and writes a program to determine whether the number sequence has been arranged in descending order, and output the judgment result.

C# split reading group with string input

using System;



namespace ConsoleApp1

{

    class Program

    {

        static void Main(string[] args)

        {

            string str = Console.ReadLine();

            string[] a = str.Split(" ");

            bool flag = true;

            

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

            {

               

                if (Convert.ToInt32(a[i]) > Convert.ToInt32(a[i-1]))

                {

                    flag = false;

                }   

            }

            if (true == flag)

            {

                Console.WriteLine("该数列已排序");

            }

            else

            {

                Console.WriteLine("该数列未排列");

            }

        }

    }

}

 

Guess you like

Origin blog.csdn.net/zstuyyyyccccbbbb/article/details/114801452