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#

Задача: Garden

Решение

Categories
Visual C#

Задача: Drunken Numbers

Описание

Всеки знае, че второто най-важно нещо в живота на програмиста е да пише код, но най-важното е да пие бира. Митко и Владко са много известни програмисти. В 19-тото световно състезание по програмиране двамата се срещнали. Състезанието се състои от N на брой рунда. Във всеки рунд двамата състезатели трябва да пият бира. Митко и Владко са много добри програмисти, затова те пият наистина много бира. Съдиите са пияни и не могат да изчислят колко бира е изпита от всеки състезател, и не могат да определят по-добрият програмист.

Решение