Advertisement
martinvalchev

Compare_Char_Arrays

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