TheBulgarianWolf

LexicographicalComparison

Dec 19th, 2019
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace LexicographicalComparison
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             //getting the char arrays as strings
  14.             string input1 = Console.ReadLine();
  15.             string input2 = Console.ReadLine();
  16.  
  17.             //transition to arrays
  18.             char[] array1 = input1.ToCharArray();
  19.             char[] array2 = input2.ToCharArray();
  20.  
  21.             int i = 0;
  22.             int j = 0;
  23.             bool equal = false;
  24.  
  25.             while(i<array1.Length && j < array2.Length)
  26.             {
  27.                 if(array1[i] > array2[j])
  28.                 {
  29.                     Console.WriteLine(input2);
  30.                     equal = false;  
  31.                     break;
  32.                 }
  33.                 else if(array1[i] < array2[j])
  34.                 {
  35.                     Console.WriteLine(input1);
  36.                     equal = false;
  37.                     break;
  38.                 }
  39.                 else
  40.                 {
  41.                     equal = true;
  42.                 }
  43.             }
  44.  
  45.             if(equal == true)
  46.             {
  47.                 if(array1.Length < array2.Length)
  48.                 {
  49.                     Console.WriteLine(array1);
  50.                 }
  51.                 else if(array1.Length > array2.Length)
  52.                 {
  53.                     Console.WriteLine(array2);
  54.                 }
  55.                 else
  56.                 {
  57.                     Console.WriteLine("No difference! ");
  58.                 }
  59.             }
  60.         }
  61.     }
  62. }
Add Comment
Please, Sign In to add comment