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 Problem_5
- {
- class Program
- {
- static void Main(string[] args)
- {
- long n = long.Parse(Console.ReadLine());
- string binary = getBinary(n);
- string output = "";
- string latest = "";
- while (true)
- {
- string cmd = Console.ReadLine();
- if (cmd == "Game Over!")
- {
- break;
- }
- if (cmd == "Odd")
- {
- for (int i = 0; i < binary.Length; i++)
- {
- if (i % 2 != 0)
- {
- output += binary[i];
- }
- }
- }
- if (cmd == "Even")
- {
- for (int i = 0; i < binary.Length; i++)
- {
- if (i % 2 == 0)
- {
- output += binary[i];
- }
- }
- }
- latest = "";
- latest = output;
- output = "";
- binary = latest;
- }
- int count = 0;
- long finalInt = Convert.ToUInt32(latest, 2);
- for (int i = 0; i < latest.Length; i++)
- {
- if (latest[i] == '1')
- {
- count++;
- }
- }
- Console.WriteLine(finalInt + " -> " + count);
- }
- static string getBinary(long n)
- {
- string bin = Convert.ToString(n, 2);
- string bin32 = new string('0', 32 - bin.Length) + bin;
- return bin32;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement