Advertisement
PolinaKoleva

CharArrayCompare

Jan 12th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.57 KB | None | 0 0
  1. using System;
  2. class Problem3CharArrayCompare
  3. {
  4.     static void Main()
  5.     {
  6.         string str1 = Console.ReadLine();
  7.         char[] arr1 = str1.ToCharArray();
  8.         int arr1Length = arr1.Length;
  9.         string str2 = Console.ReadLine();
  10.         char[] arr2 = str2.ToCharArray();
  11.         int arr2Length = arr2.Length;
  12.         bool equal = true;
  13.         if(arr1Length != arr2Length)
  14.          {
  15.              equal = false;
  16.              if(arr1Length>arr2Length)
  17.              {
  18.                  Console.WriteLine("The first array is lexicographically first");
  19.              }
  20.              else
  21.              {
  22.                  Console.WriteLine("The second array is lexicographically first");
  23.              }
  24.          }
  25.          else
  26.          {
  27.             for (int i = 0; i < arr1Length; i++)
  28.             {
  29.                 if(arr1[i] == arr2[i])
  30.                     {
  31.                         continue;
  32.                     }
  33.                     else
  34.                     {
  35.                         equal = false;
  36.                         if (arr1[i] > arr2[i])
  37.                         {
  38.                             Console.WriteLine("The second array is lexicographically first");
  39.                         }
  40.                         else
  41.                         {
  42.                             Console.WriteLine("The first array is lexicographically first");
  43.                         }
  44.                     }
  45.             }
  46.          }
  47.          if (equal == true)
  48.          {
  49.              Console.WriteLine("The two arrays are equal lexicographically");
  50.          }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement