Advertisement
bacco

Compare Char Arrays

May 6th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.67 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace test
  5. {
  6.     class MainClass
  7.     {
  8.         public static void Main()
  9.         {
  10.             char[] arrFirst = Console.ReadLine()
  11.                                      .Split(' ')
  12.                                        .Select(char.Parse)
  13.                                          .ToArray();
  14.             char[] arrSecond = Console.ReadLine()
  15.                                         .Split(' ')
  16.                                           .Select(char.Parse)
  17.                                             .ToArray();
  18.  
  19.             bool isTheFirstArr = false;
  20.  
  21.  
  22.             for (int i = 0; i < Math.Min(arrFirst.Length, arrSecond.Length); i++)
  23.             {
  24.                 if (arrFirst[i] < arrSecond[i])
  25.                 {
  26.                     isTheFirstArr = true;
  27.                 }
  28.                 else if (arrFirst[i] > arrSecond[i])
  29.                 {
  30.                     isTheFirstArr = false;
  31.                 }
  32.                 else
  33.                 {
  34.                     if (arrFirst.Length > arrSecond.Length)
  35.                     {
  36.                         isTheFirstArr = false;
  37.                     }
  38.                     else
  39.                     {
  40.                         isTheFirstArr = true;
  41.                     }
  42.                 }
  43.             }
  44.  
  45.             if (isTheFirstArr)
  46.             {
  47.                 Console.WriteLine(string.Join("", arrFirst));
  48.                 Console.WriteLine(string.Join("", arrSecond));
  49.             }
  50.             else
  51.             {
  52.                 Console.WriteLine(string.Join("", arrDown));
  53.                 Console.WriteLine(string.Join("", arrUp));
  54.             }
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement