Advertisement
Guest User

Untitled

a guest
Apr 1st, 2015
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace GameOfBits
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. long startNum = long.Parse(Console.ReadLine());
  14. List<char> arr = Convert.ToString(startNum, 2).ToList();
  15. string comm = Console.ReadLine();
  16.  
  17. while(!comm.Contains("Game Over!"))
  18. {
  19. if(comm=="Odd")
  20. {
  21. for (int i = arr.Count-2; i >=0; i-=2)
  22. {
  23. arr.RemoveAt(i);
  24. }
  25. }
  26. else
  27. {
  28. for (int i = arr.Count - 1; i >= 0; i -= 2)
  29. {
  30. arr.RemoveAt(i);
  31. }
  32. }
  33. comm = Console.ReadLine();
  34. }
  35. int result = 0;
  36. int countBits = 0;
  37. for (int i = arr.Count-1; i >=0; i--)
  38. {
  39. result+=int.Parse(arr[i].ToString())*(int)Math.Pow(2,arr.Count-1-i);
  40. if(arr[i]=='1')
  41. {
  42. countBits++;
  43. }
  44. }
  45. Console.WriteLine("{0} -> {1}", result, countBits);
  46. }
  47. }
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement