Advertisement
Guest User

orgBitPlay

a guest
Mar 30th, 2015
270
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 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 ConsoleApplication5
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. long number = long.Parse(Console.ReadLine());
  14.  
  15. while (true)
  16. {
  17. string command = Console.ReadLine();
  18. if (command == "Game Over!")
  19. {
  20. break;
  21. }
  22.  
  23. string num = "";
  24. string numbrAsString = Convert.ToString(number, 2);
  25. for (int pos = 0; pos < numbrAsString.Length; pos++)
  26. {
  27. int tmp = pos + 1;
  28. if (command == "Odd")
  29. {
  30. if (tmp % 2 != 0)
  31. {
  32. long bit = 1 & number >> pos;
  33. num = bit.ToString() + num;
  34. }
  35. }
  36. else
  37. {
  38. if (tmp % 2 == 0)
  39. {
  40. long bit = 1 & number >> pos;
  41. num = bit.ToString() + num;
  42. }
  43. }
  44. }
  45. //Console.WriteLine(num);
  46. number = Convert.ToInt64(num, 2);
  47. }
  48.  
  49. int bitCount = 0;
  50. string numAsString = Convert.ToString(number, 2);
  51. for (int i = 0; i < numAsString.Length; i++)
  52. {
  53. if (numAsString[i] == '1')
  54. {
  55. bitCount++;
  56. }
  57. }
  58.  
  59. Console.WriteLine("{0} -> {1}", number, bitCount);
  60.  
  61. }
  62. }
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement