Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FallDown
- {
- static void Main()
- {
- int n = 8;
- uint[] numbers = new uint[n];
- for (int i = 0; i < n; i++)
- {
- string number = Console.ReadLine();
- numbers[i] = UInt32.Parse(number);
- }
- int[] onesInCol = new int[n];
- // get the 1's count in each column
- for (int col = 0; col < n; col++)
- {
- uint mask = 1U << col;
- for (int i = 0; i < n; i++)
- {
- if ((numbers[i] & mask) != 0)
- {
- onesInCol[col]++;
- }
- }
- }
- uint[] newNumbers = new uint[n];
- // set the 1's in the respective columns of the numbers - bottom-up
- for (int col = 0; col < n; col++)
- {
- int i = n - 1;
- uint mask = 1U << col;
- while (onesInCol[col] > 0)
- {
- newNumbers[i] |= mask;
- onesInCol[col]--;
- i--;
- }
- }
- for (int i = 0; i < n; i++)
- {
- Console.WriteLine(newNumbers[i]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement