Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- class FallDown
- {
- static void Main()
- {
- int[] initial = new int[8];
- int[] afterFall = new int[8];
- int[] countFull = new int[8];
- //enter initial field
- for (int i = 0; i < initial.Length; i++)
- {
- initial[i] = int.Parse(Console.ReadLine());
- }
- //count full cells on each position
- for (int shift = 0; shift < 8; shift++)
- {
- for (int element = 0; element < 8; element++)
- {
- if (((initial[element] >> shift) & 1) == 1)
- {
- countFull[shift]++;
- }
- }
- }
- //fill positions
- for (int shift = 0; shift < 8; shift++)
- {
- for (int i = 7; i >= 0; i--)
- {
- if (countFull[shift] > 0)
- {
- afterFall[i] = afterFall[i] | (1 << shift);
- countFull[shift]--;
- }
- else
- {
- break;
- }
- }
- }
- //write output
- foreach (int ready in afterFall)
- {
- Console.WriteLine(ready);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement