Advertisement
Guest User

Is a list sorted ?

a guest
Oct 5th, 2019
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _04_Is_a_List_Sorted
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int nLines = int.Parse(Console.ReadLine());
  12.             List<int> operatedList = new List<int>();
  13.             List<bool> result = new List<bool>(nLines);
  14.             bool isTrue = true;
  15.             for (int i = 0; i < nLines; i++)
  16.             {
  17.                 operatedList = Console.ReadLine()
  18.                        .Split(',')
  19.                        .Select(int.Parse)
  20.                        .ToList();
  21.                 for (int j = 0; j < operatedList.Count - 1; j++)
  22.                 {
  23.                     if (operatedList[j] > operatedList[j + 1])
  24.                     {
  25.                         isTrue = false;
  26.                         break;
  27.                     }
  28.                 }
  29.                 result.Add(isTrue);
  30.             }
  31.             foreach (var item in result)
  32.             {
  33.                 Console.WriteLine(item);
  34.             }
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement