Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication5
- {
- class Program
- {
- static void Main(string[] args)
- {
- long number = long.Parse(Console.ReadLine());
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "Game Over!")
- {
- break;
- }
- string num = "";
- string numbrAsString = Convert.ToString(number, 2);
- for (int pos = 0; pos < numbrAsString.Length; pos++)
- {
- int tmp = pos + 1;
- if (command == "Odd")
- {
- if (tmp % 2 != 0)
- {
- long bit = 1 & number >> pos;
- num = bit.ToString() + num;
- }
- }
- else
- {
- if (tmp % 2 == 0)
- {
- long bit = 1 & number >> pos;
- num = bit.ToString() + num;
- }
- }
- }
- //Console.WriteLine(num);
- number = Convert.ToInt64(num, 2);
- }
- int bitCount = 0;
- string numAsString = Convert.ToString(number, 2);
- for (int i = 0; i < numAsString.Length; i++)
- {
- if (numAsString[i] == '1')
- {
- bitCount++;
- }
- }
- Console.WriteLine("{0} -> {1}", number, bitCount);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement