Advertisement
xellscream

LetterByLetter

Jan 8th, 2013
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. using System;
  2.  
  3. class LetterByLetter
  4. {
  5.     static void Main()
  6.     {
  7.         Console.WriteLine("Enter size for the first array: ");
  8.         int One = int.Parse(Console.ReadLine());
  9.         Console.WriteLine();
  10.  
  11.         Console.WriteLine("Type the word letter by letter.");
  12.         char [] arrOne = new char[One];
  13.         for(int index = 0; index < One; index++)
  14.         {
  15.             arrOne [index] = char.Parse(Console.ReadLine());
  16.         }
  17.         Console.WriteLine();
  18.  
  19.         Console.WriteLine("Enter size for the second array: ");
  20.         int Two = int.Parse(Console.ReadLine());
  21.         Console.WriteLine();
  22.  
  23.         Console.WriteLine("Type the word letter by letter.");
  24.         char[] arrTwo = new char [Two];
  25.         for(int index = 0; index < Two; index++)
  26.         {
  27.             arrTwo [index] = char.Parse(Console.ReadLine());
  28.         }
  29.  
  30.         bool even = true;
  31.         int maxLenght;
  32.         if(One > Two)
  33.         {
  34.             maxLenght = Two;
  35.         }
  36.         else if (One < Two)
  37.         {
  38.             maxLenght = One;
  39.         }
  40.         else
  41.         {
  42.             maxLenght = One;
  43.         }
  44.  
  45.  
  46.         for (int index = 0; index < maxLenght; index++)
  47.         {
  48.             if (arrOne[index] < arrTwo[index])
  49.             {
  50.                 Console.WriteLine("The first array is lexicografically first.");
  51.                 even = false;
  52.                 break;
  53.             }
  54.             else if (arrOne[index] > arrTwo[index])
  55.             {
  56.                 Console.WriteLine("The second array is lexicografically first.");
  57.                 even = false;
  58.                 break;
  59.             }
  60.             else
  61.             {
  62.                 even = true;
  63.                 continue;
  64.             }
  65.         }
  66.  
  67.         if (even == true)
  68.         {
  69.             if (One < Two)
  70.             {
  71.                 Console.WriteLine("The first array is lexicografically first.");
  72.             }
  73.             else if (One > Two)
  74.             {
  75.                 Console.WriteLine("The second array is lexicografically first.");
  76.             }
  77.             else
  78.             {
  79.                 Console.WriteLine("Both arrays are even.");
  80.             }
  81.         }
  82.     }
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement