Advertisement
Naralex

CompareCharArrays

Jan 12th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.12 KB | None | 0 0
  1. using System;
  2.  
  3. class CompareCharArrays
  4. {
  5.     static void Main()
  6.     {
  7.         string a = Console.ReadLine();
  8.         string b = Console.ReadLine();
  9.  
  10.         char[] array1 = a.ToCharArray();
  11.         char[] array2 = b.ToCharArray();
  12.  
  13.         int minLenght = Math.Min(array1.Length, array2.Length);
  14.  
  15.         int count1 = 0;
  16.         int count2 = 0;
  17.  
  18.         for (int i = 0; i < minLenght; i++)
  19.         {
  20.                 if (array1[i] < array2[i])
  21.                 {
  22.                     count1++;
  23.                 }
  24.                 if (array1[i] > array2[i])
  25.                 {
  26.                     count2++;
  27.                 }
  28.        }
  29.  
  30.             if (count1 > count2)
  31.             {
  32.                 Console.WriteLine("{0} is first.", a);
  33.                 Console.WriteLine("{0} is second.", b);
  34.             }
  35.             if (count1 == count2)
  36.             {
  37.                 Console.WriteLine("They are the same!");
  38.             }
  39.             if (count1 < count2)
  40.             {
  41.                 Console.WriteLine("{0} is first.", b);
  42.                 Console.WriteLine("{0} is second.", a);
  43.             }
  44.       }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement