Advertisement
bacco

Compare Char Arrays

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