Advertisement
zh_stoqnov

Game of Bits

Mar 30th, 2015
404
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.90 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 Problem_5
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. long n = long.Parse(Console.ReadLine());
  14. string binary = getBinary(n);
  15. string output = "";
  16. string latest = "";
  17. while (true)
  18. {
  19. string cmd = Console.ReadLine();
  20. if (cmd == "Game Over!")
  21. {
  22. break;
  23. }
  24. if (cmd == "Odd")
  25. {
  26. for (int i = 0; i < binary.Length; i++)
  27. {
  28. if (i % 2 != 0)
  29. {
  30. output += binary[i];
  31. }
  32. }
  33. }
  34. if (cmd == "Even")
  35. {
  36. for (int i = 0; i < binary.Length; i++)
  37. {
  38. if (i % 2 == 0)
  39. {
  40. output += binary[i];
  41. }
  42. }
  43. }
  44. latest = "";
  45. latest = output;
  46. output = "";
  47. binary = latest;
  48. }
  49. int count = 0;
  50. long finalInt = Convert.ToUInt32(latest, 2);
  51. for (int i = 0; i < latest.Length; i++)
  52. {
  53. if (latest[i] == '1')
  54. {
  55. count++;
  56. }
  57. }
  58. Console.WriteLine(finalInt + " -> " + count);
  59. }
  60.  
  61. static string getBinary(long n)
  62. {
  63. string bin = Convert.ToString(n, 2);
  64. string bin32 = new string('0', 32 - bin.Length) + bin;
  65. return bin32;
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement