Categories
Visual C# Телерик

Задача: Pillars

Решение

using System;

namespace Pillars {
  class Program {
    static void Main() {
      int length = 8;
      int[] numbers = new int[8];
      int[] sum = new int[8];

      for (int i = 0; i < length; i++) {
        numbers[i] = int.Parse(Console.ReadLine());
      }
      for (int i = 0; i < length; i++) {
        int mask = 1 << i;
        for (int j = 0; j < length; j++) {
          int numberAndMask = numbers[j] & mask;
          int bit = numberAndMask >> i;
          if (bit == 1) {
            sum[i] += 1;
          }
        }
      }

      int leftMostColumn = -1;
      int fullCellsCount = 0;
      for (int i = 0; i < length; i++) {
        int rightSum = 0;
        for (int j = 0; j < i; j++) {
          rightSum += sum[j];
        }
        int leftSum = 0;
        for (int k = i + 1; k < length; k++) {
          leftSum += sum[k];
        }
        if (leftSum == rightSum) {
          leftMostColumn = i;
          fullCellsCount = leftSum;
        }
      }
      if (leftMostColumn >= 0) {
        Console.WriteLine(leftMostColumn);
        Console.WriteLine(fullCellsCount);
      } else {
        Console.WriteLine("No");
      }
    }
  }
}