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 GameOfBits
- {
- class Program
- {
- static void Main(string[] args)
- {
- long startNum = long.Parse(Console.ReadLine());
- List<char> arr = Convert.ToString(startNum, 2).ToList();
- string comm = Console.ReadLine();
- while(!comm.Contains("Game Over!"))
- {
- if(comm=="Odd")
- {
- for (int i = arr.Count-2; i >=0; i-=2)
- {
- arr.RemoveAt(i);
- }
- }
- else
- {
- for (int i = arr.Count - 1; i >= 0; i -= 2)
- {
- arr.RemoveAt(i);
- }
- }
- comm = Console.ReadLine();
- }
- int result = 0;
- int countBits = 0;
- for (int i = arr.Count-1; i >=0; i--)
- {
- result+=int.Parse(arr[i].ToString())*(int)Math.Pow(2,arr.Count-1-i);
- if(arr[i]=='1')
- {
- countBits++;
- }
- }
- Console.WriteLine("{0} -> {1}", result, countBits);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement