andreykata

ArraysExercise03

Jan 12th, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.54 KB | None | 0 0
  1. using System;
  2.  
  3.     class Exercise03
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             char[] arryaOne = { 'a', 'b', 'c', 'd' };
  8.             char[] arryaTwo = { 'a', 'b', 'b', 'd', 'e' };
  9.             int lengthArrayOne = arryaOne.Length;
  10.             int lengthArrayTwo = arryaTwo.Length;
  11.             int minLength = Math.Min(lengthArrayOne, lengthArrayTwo);
  12.             int equalLetters = 0;
  13.             for (int i = 0; i < minLength; i++)
  14.             {
  15.                 if (arryaOne[i] == arryaTwo[i])
  16.                 {
  17.                     equalLetters++;
  18.                 }
  19.                 else if (arryaOne[i] < arryaTwo[i])
  20.                 {
  21.                     Console.WriteLine("arrayOne is first lexicographically");
  22.                     break;
  23.                 }
  24.                 else
  25.                 {
  26.                     Console.WriteLine("arrayTwo is first lexicographically");
  27.                     break;
  28.                 }
  29.             }
  30.  
  31.             if ((equalLetters == minLength) && (lengthArrayOne == lengthArrayTwo))
  32.             {
  33.                 Console.WriteLine("Two arrays are the same");
  34.             }
  35.             else if ((equalLetters == minLength) && (lengthArrayOne < lengthArrayTwo))
  36.             {
  37.                 Console.WriteLine("arrayOne is first lexicographically");
  38.             }
  39.             else if ((equalLetters == minLength) && (lengthArrayOne > lengthArrayTwo))
  40.             {
  41.                 Console.WriteLine("arrayTwo is first lexicographically");
  42.             }
  43.         }
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment