Advertisement
Asinka

05. FallDown (TestExam)

Dec 26th, 2012
40
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.21 KB | None | 0 0
  1. using System;
  2.  
  3.  
  4.  
  5. class FallDown
  6. {
  7.     static void Main()
  8.     {
  9.         byte[] array = new byte[8];
  10.         byte[] result = new byte[8];
  11.        
  12.  
  13.         for (byte i = 0; i < 8; i++)
  14.         {
  15.             byte number = byte.Parse(Console.ReadLine());
  16.             for (int j = 0; j < 8; j++)
  17.             {
  18.                 byte mask = (byte)(1 << j);
  19.                 byte bit = (byte)(number & mask);
  20.                 bit = (byte)(bit >> j);
  21.                 array[j] += bit;              
  22.             }
  23.         }
  24.  
  25.         for (byte k = 0; k < 8; k++)
  26.         {
  27.             for (byte j = 0; j < 8; j++)
  28.             {
  29.                 if (array[j] > 0)
  30.                 {
  31.                     byte count = 0;
  32.                     count = (byte)(1 << j);
  33.                     result[k] += count;
  34.                     array[j]--;
  35.                 }
  36.             }                  
  37.         }
  38.  
  39.         Console.WriteLine(result[7]);
  40.         Console.WriteLine(result[6]);
  41.         Console.WriteLine(result[5]);
  42.         Console.WriteLine(result[4]);
  43.         Console.WriteLine(result[3]);
  44.         Console.WriteLine(result[2]);
  45.         Console.WriteLine(result[1]);
  46.         Console.WriteLine(result[0]);
  47.  
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement