IvanBorisovG

Compare Char Arrays

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