mellowdeep

Wiggle Wiggle

Dec 5th, 2015
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.50 KB | None | 0 0
  1. using System;
  2.  
  3. class WiggleWiggle
  4. {
  5.     public static string firstNum = string.Empty;
  6.     public static string secondNum = string.Empty;
  7.  
  8.     static void Main()
  9.     {
  10.         string input = Console.ReadLine();
  11.         string[] array = input.Split(' ');
  12.        
  13.         for (int i = 0; i < array.Length; i += 2)
  14.         {
  15.             Wiggle(Convert.ToInt64(array[i]), Convert.ToInt64(array[i + 1]));
  16.             InvertBits(secondNum);
  17.             InvertBits(firstNum);
  18.             firstNum = string.Empty;
  19.             secondNum = string.Empty;
  20.         }
  21.     }
  22.  
  23.  
  24.     public static void Wiggle(long numOne, long numTwo)
  25.     {
  26.         string first = Convert.ToString(numOne, 2).PadLeft(64, '0');
  27.         string second = Convert.ToString(numTwo, 2).PadLeft(64, '0');
  28.  
  29.         for (int i = first.Length-1; i > 0; i--)
  30.         {
  31.             if (i % 2 == 0)
  32.             {
  33.                 firstNum = second[i] + firstNum;
  34.                 secondNum = first[i] + secondNum;
  35.             }
  36.             else
  37.             {
  38.                 firstNum = first[i] + firstNum;
  39.                 secondNum = second[i] + secondNum;
  40.             }
  41.         }
  42.      }
  43.  
  44.     public static void InvertBits(string bitOne)
  45.     {
  46.  
  47.         string output = string.Empty;
  48.         for (int i = 0; i < bitOne.Length; i++)
  49.         {
  50.            
  51.             output += (bitOne[i] == '0' ? '1' : '0');
  52.         }
  53.         Console.WriteLine("{0} {1}",Convert.ToUInt64(output, 2), output);
  54.         output = string.Empty;
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment