Categories
Visual C# Телерик

Задача: Tribonacci Triangle

Решение

using System;

namespace TribonacciTriangle {
  class Program {
    static void Main() {
      long firstNumber = long.Parse(Console.ReadLine());
      long secondNumber = long.Parse(Console.ReadLine());
      long thirdNumber = long.Parse(Console.ReadLine());
      int linesCount = int.Parse(Console.ReadLine());

      Console.WriteLine(firstNumber);
      Console.WriteLine(secondNumber + " " + thirdNumber);

      int membersCount = 0;
      for (int i = 1; i <= linesCount; i++) {
        membersCount += i;
      }
      int nextLine = 3;
      int lineSize = 0;
      for (int i = 4; i <= membersCount; i++) {
        long currentNumber = firstNumber + secondNumber + thirdNumber;
        firstNumber = secondNumber;
        secondNumber = thirdNumber;
        thirdNumber = currentNumber;
        Console.Write(currentNumber + " ");
        lineSize++;
        if (lineSize == nextLine) {
          Console.WriteLine();
          nextLine += 1;
          lineSize = 0;
        }
      }
    }
  }
}
Categories
Visual C# Телерик

Задача: Sheets

Решение

using System;
using System.Collections.Generic;

namespace Sheets {
  class Program {
    static void Main() {
      int n = int.Parse(Console.ReadLine());
      int[] piecesList = new int[11];
      Dictionary sheets = new Dictionary();
      sheets.Add(0, "A0");
      sheets.Add(1, "A1");
      sheets.Add(2, "A2");
      sheets.Add(3, "A3");
      sheets.Add(4, "A4");
      sheets.Add(5, "A5");
      sheets.Add(6, "A6");
      sheets.Add(7, "A7");
      sheets.Add(8, "A8");
      sheets.Add(9, "A9");
      sheets.Add(10, "A10");

      piecesList[10] = 1;
      for (int i = 9; i >= 0; i--) {
        piecesList[i] = piecesList[i + 1] * 2;
      }

      for (int i = 0; i < piecesList.Length; i++) {
        if (n >= piecesList[i]) {
          n -= piecesList[i];
          sheets.Remove(i);
        }
      }

      foreach(var item in sheets) {
        Console.WriteLine(item.Value);
      }
    }
  }
}
Categories
Visual C# Телерик

Задача: Next Day

Решение

using System;

namespace TelerikExamples {
  class FireInTheMatrix {
    static void Main() {
      int fireWidth = int.Parse(Console.ReadLine());
      int sideDots = (fireWidth - 2) / 2;
      int middleDots = 0;

      for (int i = sideDots; i >= 0; i--) {
        Console.Write(new string('.', i));
        Console.Write(new string('#', 1));
        Console.Write(new string('.', middleDots));
        Console.Write(new string('#', 1));
        Console.Write(new string('.', i));
        Console.WriteLine();

        middleDots += 2;
      }

      middleDots = fireWidth - 2;

      for (int i = 0; i < fireWidth / 4; i++) {
        Console.Write(new string('.', i));
        Console.Write(new string('#', 1));
        Console.Write(new string('.', middleDots));
        Console.Write(new string('#', 1));
        Console.Write(new string('.', i));
        Console.WriteLine();
        middleDots -= 2;
      }
      Console.WriteLine(new string('-', fireWidth));
      int middleSlashes = fireWidth / 2;
      for (int i = 0; i < fireWidth / 2; i++) {
        Console.Write(new string('.', i));
        Console.Write(new string('\\', middleSlashes));
        Console.Write(new string('/', middleSlashes));
        Console.Write(new string('.', i));
        Console.WriteLine();
        middleSlashes--;
      }
    }
  }
}
Categories
Visual C# Телерик

Задача: Formula Bit 1

Решение

using System;

namespace FormulaBit1 {
  class Program {
    static int gridSize = 8;
    static int[, ] grid = new int[gridSize, gridSize];
    static int trackLength = 0;
    static int turnsCount = 0;
    static char previousDirection = 'D';
    static bool finished = false;

    static void Main() {
      for (int i = 0; i < gridSize; i++) {
        int number = int.Parse(Console.ReadLine());
        for (int j = 0; j < gridSize; j++) {
          int mask = 1 << j;
          int numberAndMask = number & mask;
          int bit = numberAndMask >> j;
          grid[i, gridSize - j - 1] = (bit == 1) ? 1 : 0;
        }
      }

      buildTrack(0, 7, 'D');

      if (finished == false) {
        Console.WriteLine("No {0}", trackLength);
      }
    }

    static void checkForTrackExit(int row, int column) {
      if (row == 7 && column == 0) {
        finished = true;
        Console.WriteLine("{0} {1}", trackLength, turnsCount);
      }
    }

    static void buildTrack(int row, int column, char currentDirection) {
      if (row < 0 || column < 0 || row >= grid.GetLength(0) || column >= grid.GetLength(1)) {
        return;
      }

      if (grid[row, column] == 1) {
        return;
      }

      switch (currentDirection) {
      case 'D':
        for (int i = row; i < gridSize; i++) {
          if (grid[i, column] == 0) {
            trackLength += 1;
            checkForTrackExit(i, column);
            if (i == (gridSize - 1)) {
              turnsCount++;
              previousDirection = 'D';
              buildTrack(i, column - 1, 'L');
            }
            continue;
          } else {
            turnsCount++;
            previousDirection = 'D';
            buildTrack(i - 1, column - 1, 'L');
            break;
          }
        }
        break;
      case 'L':
        for (int i = column; i >= 0; i--) {
          if (grid[row, i] == 0) {
            trackLength += 1;
            checkForTrackExit(row, i);
            if (i == 0) {
              if (previousDirection == 'D') {
                turnsCount++;
                previousDirection = 'L';
                buildTrack(row - 1, i, 'U');
              } else {
                turnsCount++;
                previousDirection = 'L';
                buildTrack(row + 1, i, 'D');
              }
            }
            continue;
          } else {
            if (previousDirection == 'U') {
              turnsCount++;
              previousDirection = 'L';
              buildTrack(row + 1, i + 1, 'D');
              break;
            } else {
              turnsCount++;
              previousDirection = 'L';
              buildTrack(row - 1, i + 1, 'U');
              break;
            }
          }

        }
        break;
      case 'U':
        for (int i = row; i >= 0; i--) {
          if (grid[i, column] == 0) {
            trackLength += 1;
            checkForTrackExit(i, column);
            if (i == 0) {
              turnsCount++;
              previousDirection = 'U';
              buildTrack(i, column - 1, 'L');
            }
            continue;
          } else {
            turnsCount++;
            previousDirection = 'U';
            buildTrack(i + 1, column - 1, 'L');
            break;
          }
        }
        break;
      }
    }
  }
}
Categories
Visual C# Телерик

Задача: Carpets

Решение

using System;

namespace Carpets {
  class Program {
    static void Main() {
      int fullSize = int.Parse(Console.ReadLine());
      int halfSize = fullSize / 2;

      for (int i = 1; i <= halfSize; i++) {
        Console.Write(new string('.', halfSize - i));
        string str = new string(' ', 2 * i);
        char[] chr = str.ToCharArray();
        for (int j = 0; j < chr.Length / 2; j++) {
          if (j % 2 == 0) {
            chr[j] = '/';
            chr[chr.Length - j - 1] = '\\';
          }
        }
        str = new string(chr);
        Console.Write(str);
        Console.Write(new string('.', halfSize - i));
        Console.WriteLine();
      }
      for (int i = 1; i <= halfSize; i++) {
        Console.Write(new string('.', i - 1));
        string str = new string(' ', 2 * (halfSize + 1) - 2 * i);
        char[] chr = str.ToCharArray();
        for (int j = 0; j < chr.Length / 2; j++) {
          if (j % 2 == 0) {
            chr[j] = '\\';
            chr[chr.Length - j - 1] = '/';
          }
        }
        str = new string(chr);
        Console.Write(str);
        Console.Write(new string('.', i - 1));
        Console.WriteLine();
      }
    }
  }
}
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");
      }
    }
  }
}
Categories
Visual C#

Constructor Chaining в C#

namespace OOP {
  class GSM {
    private string model;
    private string manufacturer;
    private decimal ? price;
    private string owner;
    private Battery battery;
    private Display display;

    public GSM(): this("Unknown Model", "Unknown Manifacturer") {}

    public GSM(string model, string manifacturer): this(model, manifacturer, null) {}

    public GSM(string model, string manifacturer, decimal ? price): this(model, manifacturer, price, null) {}

    public GSM(string model, string manifacturer, decimal ? price, string owner): this(model, manifacturer, price, owner, null) {}

    public GSM(string model, string manifacturer, decimal ? price, string owner, Battery battery): this(model, manifacturer, price, owner, battery, null) {}

    public GSM(string model, string manifacturer, decimal ? price, string owner, Battery battery, Display display) {
      this.model = model;
      this.manufacturer = manifacturer;
      this.price = price;
      this.owner = owner;
      this.battery = battery;
      this.display = display;
    }
  }
}
Categories
Visual C#

Задача: Bat Goiko Tower

Описание

Бат’ Гойко е известен български строител. Той прекарал по-голямата част от живота си в строене на магистрали. Той бил толкова добър в работата си, че по едно време не останало място за строене на нови магистрали. Бат’ Гойко бил много разочарован и решил да се премести във Франция, за да има повече пространство за неговите бъдещи проекти. Часове след като се приземил в Париж, брилянтна идея го озарила. Той решил да строи Айфелови кули, за да бъде по-ефективен откъм пространство. Качил се на първия самолет за България и започнал да строи кули в родината си.

Решение

Categories
Visual C#

Задача: Garden

Решение