Advertisement
sylviapsh

Lucky Numbers

Dec 27th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2.   class Lucky
  3. {
  4.   static void Main()
  5.   {
  6.     //Telerik Academy
  7.     //Two lucky numbers of 4s and 7s are entered on the console. Find the minimum operations needed to make them equal. The 2 possible operations are pair exchange or setting 4 to 7 and vice versa.
  8.     string a = Console.ReadLine(),
  9.            b = Console.ReadLine();
  10.  
  11.     a = a.Replace('4', '0');
  12.     a = a.Replace('7', '1');
  13.     b = b.Replace('4', '0');
  14.     b = b.Replace('7', '1');
  15.  
  16.     int numsLenght = a.Length;
  17.     int count0s = 0,
  18.         count1s = 0;
  19.        
  20.  
  21.     for (int bitposition = 0; bitposition < numsLenght; bitposition++)
  22.     {
  23.       if (a[bitposition] != b[bitposition])
  24.       {
  25.         if (a[bitposition] == '0')
  26.         {
  27.           count0s++;
  28.         }
  29.         else
  30.         {
  31.           count1s++;
  32.         }
  33.       }
  34.     }
  35.  
  36.     int result = Math.Max(count0s, count1s);
  37.     Console.WriteLine(result);
  38.   }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement