Created
April 10, 2015 20:23
-
-
Save EBojilova/8dfab658f536e8156330 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class GameOfBits | |
{ | |
static void Main(string[] args) | |
{ | |
uint number = uint.Parse(Console.ReadLine()); | |
//Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0')); | |
string command; | |
uint count1 = 0; | |
while (!(string.IsNullOrEmpty(command = Console.ReadLine()) || command == "Game Over!")) | |
{ | |
uint newNum = 0; | |
uint currentNum = 0; | |
count1 = 0; | |
if (command == "Even") | |
{ | |
number >>= 1; | |
} | |
for (int i = 0, iNew = 0; i < 32; i += 2, iNew++) | |
{ | |
currentNum = (number >> i) & 1; | |
count1 += currentNum; | |
newNum |= currentNum << iNew; | |
} | |
number = newNum; | |
//Console.WriteLine(Convert.ToString(number, 2).PadLeft(32, '0')); | |
} | |
Console.WriteLine("{0} -> {1}", number, count1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment