archangelmihail

FallDownBitwiseSolution

Dec 1st, 2013
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.80 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 FallDown
  8. {
  9.     class FallDown
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             // solution with bit operations
  14.             //input
  15.             int n0 = int.Parse(Console.ReadLine());
  16.             int n1 = int.Parse(Console.ReadLine());
  17.             int n2 = int.Parse(Console.ReadLine());
  18.             int n3 = int.Parse(Console.ReadLine());
  19.             int n4 = int.Parse(Console.ReadLine());
  20.             int n5 = int.Parse(Console.ReadLine());
  21.             int n6 = int.Parse(Console.ReadLine());
  22.             int n7 = int.Parse(Console.ReadLine());
  23.             // variables inicialization
  24.  
  25.  
  26.             //body
  27.             for (int i = 0; i < 8; i++)
  28.             {
  29.                 for (int bitPosition = 0; bitPosition < 8; bitPosition++)
  30.                 {
  31.                     if (((n7 >> bitPosition) & 1) == 0 && ((n6 >> bitPosition) & 1) == 1)
  32.                     {
  33.                         n7 |= (1 << bitPosition);
  34.                         n6 ^= (1 << bitPosition);   // or n6 &= -(1 << bitPosition);
  35.                     }
  36.                 }
  37.                 for (int bitPosition = 0; bitPosition < 8; bitPosition++)
  38.                 {
  39.                     if (((n6 >> bitPosition) & 1) == 0 && ((n5 >> bitPosition) & 1) == 1)
  40.                     {
  41.                         n6 |= (1 << bitPosition);
  42.                         n5 ^= (1 << bitPosition);   // or n6 &= -(1 << bitPosition);
  43.                     }
  44.                 }
  45.                 for (int bitPosition = 0; bitPosition < 8; bitPosition++)
  46.                 {
  47.                     if (((n5 >> bitPosition) & 1) == 0 && ((n4 >> bitPosition) & 1) == 1)
  48.                     {
  49.                         n5 |= (1 << bitPosition);
  50.                         n4 ^= (1 << bitPosition);   // or n6 &= -(1 << bitPosition);
  51.                     }
  52.                 }
  53.                 for (int bitPosition = 0; bitPosition < 8; bitPosition++)
  54.                 {
  55.                     if (((n4 >> bitPosition) & 1) == 0 && ((n3 >> bitPosition) & 1) == 1)
  56.                     {
  57.                         n4 |= (1 << bitPosition);
  58.                         n3 ^= (1 << bitPosition);   // or n6 &= -(1 << bitPosition);
  59.                     }
  60.                 }
  61.                 for (int bitPosition = 0; bitPosition < 8; bitPosition++)
  62.                 {
  63.                     if (((n3 >> bitPosition) & 1) == 0 && ((n2 >> bitPosition) & 1) == 1)
  64.                     {
  65.                         n3 |= (1 << bitPosition);
  66.                         n2 ^= (1 << bitPosition);   // or n6 &= -(1 << bitPosition);
  67.                     }
  68.                 }
  69.                 for (int bitPosition = 0; bitPosition < 8; bitPosition++)
  70.                 {
  71.                     if (((n2 >> bitPosition) & 1) == 0 && ((n1 >> bitPosition) & 1) == 1)
  72.                     {
  73.                         n2 |= (1 << bitPosition);
  74.                         n1 ^= (1 << bitPosition);   // or n6 &= -(1 << bitPosition);
  75.                     }
  76.                 }
  77.                 for (int bitPosition = 0; bitPosition < 8; bitPosition++)
  78.                 {
  79.                     if (((n1 >> bitPosition) & 1) == 0 && ((n0 >> bitPosition) & 1) == 1)
  80.                     {
  81.                         n1 |= (1 << bitPosition);
  82.                         n0 ^= (1 << bitPosition);   // or n6 &= -(1 << bitPosition);
  83.                     }
  84.                 }
  85.             }
  86.  
  87.             //output
  88.             Console.WriteLine(n0);
  89.             Console.WriteLine(n1);
  90.             Console.WriteLine(n2);
  91.             Console.WriteLine(n3);
  92.             Console.WriteLine(n4);
  93.             Console.WriteLine(n5);
  94.             Console.WriteLine(n6);
  95.             Console.WriteLine(n7);
  96.         }
  97.     }
  98. }
Advertisement
Add Comment
Please, Sign In to add comment