VelizarAvramov

05. Compare Char Arrays

Nov 25th, 2018
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _05._Compare_Char_Arrays_Veronika
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             char[] firstInput = Console.ReadLine().
  11.                 Split().Select(char.Parse).ToArray();
  12.             char[] secondInput = Console.ReadLine().
  13.                 Split().Select(char.Parse).ToArray();
  14.  
  15.             int minLength = Math.Min(firstInput.Length, secondInput.Length);
  16.             if (firstInput.Length == secondInput.Length)
  17.             {
  18.                 for (int i = 0; i < firstInput.Length; i++)
  19.                 {
  20.                     if (firstInput[i] > secondInput[i])
  21.                     {
  22.                         Console.WriteLine(string.Join("", secondInput));
  23.                         Console.WriteLine(string.Join("", firstInput));
  24.                         break;
  25.                     }
  26.                     else
  27.                     {
  28.                         Console.WriteLine(string.Join("", firstInput));
  29.                         Console.WriteLine(string.Join("", secondInput));
  30.                         break;
  31.                     }
  32.                 }
  33.             }
  34.             else
  35.             {
  36.                 for (int i = 0; i < minLength; i++)
  37.                 {
  38.                     if (firstInput.Length > secondInput.Length)
  39.                     {
  40.                         if (firstInput[i] == secondInput[i])
  41.                         {
  42.                             Console.WriteLine(string.Join("",secondInput));
  43.                             Console.WriteLine(string.Join("",firstInput));
  44.                             break;
  45.                         }
  46.                         else if (firstInput[i] > secondInput.Length)
  47.                         {
  48.                             Console.WriteLine(string.Join("", secondInput));
  49.                             Console.WriteLine(string.Join("", firstInput));
  50.                             break;
  51.                         }
  52.                         else
  53.                         {
  54.                             Console.WriteLine(string.Join("", firstInput));
  55.                             Console.WriteLine(string.Join("", secondInput));
  56.                             break;
  57.                         }
  58.                     }
  59.                     else if (firstInput.Length < secondInput.Length)
  60.                     {
  61.                         if (firstInput[i] == secondInput[i])
  62.                         {
  63.                             Console.WriteLine(string.Join("", firstInput));
  64.                             Console.WriteLine(string.Join("", secondInput));
  65.                             break;
  66.                         }
  67.                         else if (firstInput[i] > secondInput.Length)
  68.                         {
  69.                             Console.WriteLine(string.Join("", firstInput));
  70.                             Console.WriteLine(string.Join("", secondInput));
  71.                             break;
  72.                         }
  73.                         else
  74.                         {
  75.                             Console.WriteLine(string.Join("", secondInput));
  76.                             Console.WriteLine(string.Join("", firstInput));
  77.                             break;
  78.                         }
  79.                     }
  80.                 }
  81.             }
  82.         }
  83.     }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment