Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class GameOfBits
- {
- static void Main()
- {
- uint number = uint.Parse(Console.ReadLine());
- string command = Console.ReadLine();
- while (command != "Game Over!")
- {
- int count = 0;
- switch (command)
- {
- case "Odd":
- count = 0;
- break;
- case "Even":
- count = 1;
- break;
- }
- uint newNumber = 0;
- int index = 0;
- for (; count <= 31; count += 2, index++)
- {
- uint currentBit = ((number >> count) & 1) << index;
- newNumber = newNumber | currentBit;
- }
- number = newNumber;
- command = Console.ReadLine();
- }
- int countOneBits = 0;
- for (int i = 0; i < 32; i++)
- {
- uint currentBit = (number >> i) & 1;
- if (currentBit == 1)
- {
- countOneBits++;
- }
- }
- Console.WriteLine("{0} -> {1}", number, countOneBits);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement