Categories
Visual C# Телерик

Задача: Neuron

Решение

using System;
using System.Collections.Generic;

namespace NeuronMapping {
  class Program {
    static void Main() {
      List numbersList = new List();
      uint inputNumber = 0;
      while (true) {
        if (uint.TryParse(Console.ReadLine(), out inputNumber)) {
          numbersList.Add(inputNumber);
        } else {
          break;
        }
      }

      for (int i = 0; i < numbersList.Count; i++) {
        for (int j = 0; j < 32; j++) {
          uint mask = (uint) 1 << j;
          uint numberAndMask = numbersList[i] & mask;
          uint bit = numberAndMask >> j;
          if (bit == 1) {
            break;
          } else {
            numbersList[i] = numbersList[i] | mask;
          }
        }
      }

      for (int i = 0; i < numbersList.Count; i++) {
        for (int j = 31; j >= 0; j--) {
          uint mask = (uint) 1 << j;
          uint numberAndMask = numbersList[i] & mask;
          uint bit = numberAndMask >> j;
          if (bit == 1) {
            break;
          } else {
            numbersList[i] = numbersList[i] | mask;
          }
        }
      }

      for (int i = 0; i < numbersList.Count; i++) {
        for (int j = 0; j < 32; j++) {
          uint mask = (uint) 1 << j;
          numbersList[i] = mask ^ numbersList[i];
        }
        Console.WriteLine(numbersList[i]);
      }
    }
  }
}
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");
      }
    }
  }
}