Advertisement
Guest User

Flipper

a guest
Dec 2nd, 2014
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5.  
  6. static class bitove
  7. {
  8. public static void Main()
  9. {
  10.  
  11. long x = long.Parse(Console.ReadLine());
  12. string s =Convert.ToString(x,2);
  13. //Console.WriteLine(s);
  14. ulong[] bits = s.Select(c => ulong.Parse(c.ToString())).ToArray();
  15. for (int i = 0; i < bits.Length-2; i++)
  16. {
  17. if ((bits[i]==bits[i+1])&(bits[i+1]==bits[i+2]))
  18. {
  19. bits[i] ^= 1;
  20. bits[i+1] ^= 1;
  21. bits[i+2] ^= 1;
  22. i += 2;
  23. }
  24. }
  25. List<ulong> output = new List<ulong>();
  26. foreach (var bit in bits)
  27. {
  28. output.Add(bit);
  29. }
  30. //for (int i = 0; i < output.Count; i++)
  31. // {
  32. // Console.Write(output[i]);
  33. // }
  34. string[] result = output.Select(c => c.ToString()).ToArray();
  35. string result2 = string.Join("", result);
  36. //Console.WriteLine();
  37. Console.WriteLine(Convert.ToUInt64(result2, 2));
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement