ユーザーは、スペースで区切った整数のリストを入力し、数列が降順であるかどうかを判別するプログラムを作成し、判定結果を出力します。

文字列入力のあるC#分割読み取りグループ

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("该数列未排列");

            }

        }

    }

}

 

おすすめ

転載: blog.csdn.net/zstuyyyyccccbbbb/article/details/114801452