Alexander7337

GameOfBitsOddEven

Jan 16th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.98 KB | None | 0 0
  1. using System;
  2.  
  3. class Program
  4. {
  5.     static void Main(string[] args)
  6.     {
  7.         uint num = uint.Parse(Console.ReadLine());
  8.         uint newNum = num;
  9.  
  10.         string command = Console.ReadLine();
  11.  
  12.         while (command.ToLower() != "game over!")
  13.         {
  14.             if (command.ToLower() == "even")
  15.             {
  16.                 num >>= 1;
  17.             }
  18.             newNum = num & 1;
  19.             num >>= 2;
  20.             int count = 1;
  21.             while (num != 0)
  22.             {
  23.                 newNum |= (num & 1) << count;
  24.                 num >>= 2;
  25.                 count++;
  26.             }
  27.             command = Console.ReadLine();
  28.             num = newNum;
  29.         }
  30.  
  31.         uint bitCounter = 0;
  32.         while (newNum > 0)
  33.         {
  34.             uint bitCheck = newNum & 1;
  35.             if (bitCheck == 1)
  36.             {
  37.                 bitCounter++;
  38.             }
  39.             newNum >>= 1;
  40.         }
  41.         Console.WriteLine("{0} -> {1}", num, bitCounter);
  42.     }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment