simonses

Untitled

Jan 6th, 2013
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.22 KB | None | 0 0
  1. using System;
  2.  
  3. class CompareTwoCharArrays
  4. {
  5.     static void Main()
  6.     {
  7.         char[] arrayOne = new char[4];
  8.         char[] arrayTwo = new char[4];
  9.         bool equal = true;
  10.  
  11.         // Read the first array
  12.         for (int i = 0; i < arrayOne.Length; i++)
  13.         {
  14.             arrayOne[i] = char.Parse(Console.ReadLine());
  15.         }
  16.  
  17.         // Read the second array
  18.         for (int i = 0; i < arrayTwo.Length; i++)
  19.         {
  20.             arrayTwo[i] = char.Parse(Console.ReadLine());
  21.         }
  22.  
  23.         // Compair the elements
  24.         for (int i = 0; i < arrayOne.Length; i++)
  25.         {
  26.             if ((arrayOne[i] != arrayTwo[i])  && (arrayOne[i] < arrayTwo[i]))
  27.             {
  28.                 equal = false;
  29.                 Console.WriteLine("The arrays are NOT equal! The first is lexicographically earlier!");
  30.                 break;
  31.             }
  32.             else if (arrayOne[i] != arrayTwo[i])
  33.             {
  34.                 equal = false;
  35.                 Console.WriteLine("The arrays are NOT equal! The second is lexicographically earlier!");
  36.                 break;
  37.             }
  38.         }
  39.         if (equal)
  40.         {
  41.             Console.WriteLine("The arrays are equal!");
  42.         }
  43.     }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment