Categories
Visual C# Телерик

C# част 2 – класиране

C# програмиране – част IIОнлайн10 от 10279 от 500Взет!
Точки: 61.10
Място: 181

 За 21 точки не е взет с отличие, но можеха да са и 121 точки.

Поуката е повече подготовка за изпита по Обектно-ориентирано програмиране (ООП).

Categories
Visual C# Телерик

Решение на задача – StrangeLand Numbers

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StrangeLandNumbers {
  class Program {
    static void Main(string[] args) {
      Dictionary strangeLandNumbersDictionay = new Dictionary();
      strangeLandNumbersDictionay.Add("f", 0);
      strangeLandNumbersDictionay.Add("bIN", 1);
      strangeLandNumbersDictionay.Add("oBJEC", 2);
      strangeLandNumbersDictionay.Add("mNTRAVL", 3);
      strangeLandNumbersDictionay.Add("lPVKNQ", 4);
      strangeLandNumbersDictionay.Add("pNWE", 5);
      strangeLandNumbersDictionay.Add("hT", 6);
      List strangeLandNumbersList = new List();
      string strangeLandNumber = Console.ReadLine();
      StringBuilder number = new StringBuilder();
      for (int index = 0; index < strangeLandNumber.Length; index++) {
        number.Append(strangeLandNumber[index]);
        if (strangeLandNumbersDictionay.ContainsKey(number.ToString())) {
          strangeLandNumbersList.Add(number.ToString());
          number.Clear();
        }
      }
      int power = strangeLandNumbersList.Count - 1;
      long sum = 0;
      for (int index = 0; index < strangeLandNumbersList.Count; index++) {
        sum += strangeLandNumbersDictionay[strangeLandNumbersList[index]] * (long) Math.Pow(7, power);
        number.Clear();
        power--;
      }
      Console.WriteLine(sum);
    }
  }
}
Categories
Visual C# Телерик

Резултат от изпита по C# – част 2

Изпита на 22.01.2014 (сутрин) приключи със среден резултат, само 279 точки, но изводите са вече направени – необходимо е повече старание и време за по-добър резултат.

Задачите бяха много интересни, а за следващия курс по C# част 2 ще се постарая да съм решил всички давани задачи до момента, плюс тези от Алго академията.

Categories
Visual C# Телерик

Решение на задача – Decode And Decrypt

using System;
using System.Text;
using System.Linq;
using System.Collections.Generic;

namespace DecodeAndDecrypt {
  class Program {
    static void Main() {
      string encodedMessage = Console.ReadLine();
      List cypherDigitsList = new List();
      for (int letterIndex = encodedMessage.Length - 1; letterIndex >= 0; letterIndex--) {
        if (Char.IsDigit(encodedMessage[letterIndex])) {
          cypherDigitsList.Add(encodedMessage[letterIndex]);
        } else {
          break;
        }
      }
      cypherDigitsList.Reverse();
      int cypherLenght = int.Parse(string.Join(string.Empty, cypherDigitsList.ToArray()));
      string decodedMessage = Decode(encodedMessage, cypherLenght.ToString().Length);
      int cypherStartIndex = decodedMessage.Length - cypherLenght;
      string cypher = decodedMessage.Substring(cypherStartIndex, cypherLenght);
      int encryptedMessageLength = decodedMessage.Length - cypher.Length;
      string encryptedMessage = decodedMessage.Substring(0, encryptedMessageLength);
      Console.WriteLine(Decrypt(encryptedMessage, cypher));
    }

    static string Decrypt(string encryptedMessage, string cypher) {
      char[] cypherText = new char[encryptedMessage.Length];
      int index = 0;
      if (cypher.Length < encryptedMessage.Length) {
        for (int i = 0; i < encryptedMessage.Length; i++) {
          if (index == cypher.Length) {
            index = 0;
          }
          cypherText[i] = (char)((FindLetterIndex((encryptedMessage[i])) ^ FindLetterIndex(cypher[index])) + 65);
          index++;
        }
      } else {
        for (int i = 0; i < cypher.Length; i++) {
          if (index == encryptedMessage.Length) {
            index = 0;
          }
          if (i >= encryptedMessage.Length) {
            cypherText[index] = (char)((FindLetterIndex((cypherText[index])) ^ FindLetterIndex(cypher[i])) + 65);
          } else {
            cypherText[index] = (char)((FindLetterIndex((encryptedMessage[index])) ^ FindLetterIndex(cypher[i])) + 65);
          }
          index++;
        }
      }
      string encryptedText = string.Join(string.Empty, cypherText);
      return encryptedText;
    }

    static string Decode(string message, int cypherDigitsCount) {
      StringBuilder decodedMessage = new StringBuilder();
      StringBuilder letterMultiplier = new StringBuilder();
      for (int i = 0; i < message.Length - cypherDigitsCount; i++) {
        if (Char.IsDigit(message[i])) {
          letterMultiplier.Append(Char.GetNumericValue(message[i]));
        } else {
          if (letterMultiplier.Length > 0) {
            decodedMessage.Append(new string(message[i], int.Parse(letterMultiplier.ToString())));
            letterMultiplier.Clear();
          } else {
            decodedMessage.Append(message[i]);
          }
        }
      }
      return decodedMessage.ToString();
    }

    static int FindLetterIndex(char letter) {
      int index = (letter < 97 ? letter - 65 : letter - 97);
      return index;
    }
  }
}
Categories
Visual C# Телерик

Решение на задача – Magic Words

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MagicWords {
  class Program {
    static List wordsList = new List();
    static int wordsCount;
    static void Main() {
      wordsCount = int.Parse(Console.ReadLine());
      for (int i = 0; i < wordsCount; i++) {
        wordsList.Add(Console.ReadLine());
      }
      if (wordsCount > 1) {
        for (int oldIndex = 0; oldIndex < wordsCount; oldIndex++) {
          int wordLength = wordsList[oldIndex].Length;
          int newIndex = wordLength % (wordsCount + 1);
          ShiftElement(oldIndex, newIndex);
        }
        Print();
      } else {
        Console.WriteLine(wordsList[0]);
      }
    }
    static void Print() {
      int maxWordLength = wordsList.Max(w => w.Length);
      StringBuilder output = new StringBuilder();
      for (int letterIndex = 0; letterIndex < maxWordLength; letterIndex++) {
        for (int wordIndex = 0; wordIndex < wordsCount; wordIndex++) {
          if (letterIndex < wordsList[wordIndex].Length) {
            output.Append(wordsList[wordIndex].ToString()[letterIndex]);
          } else {
            continue;
          }
        }
      }
      Console.WriteLine(output.ToString());
    }
    static void ShiftElement(int oldIndex, int newIndex) {
      string word = wordsList[oldIndex];
      wordsList[oldIndex] = null;
      wordsList.Insert(newIndex, word);
      wordsList.Remove(null);
    }
  }
}
Categories
Visual C# Телерик

Решение на задача – Multiverse Communication

using System;
using System.Collections.Generic;
using System.Text;

namespace MultiverseCommunication {
  class Program {
    static void Main() {
      Dictionary digits = new Dictionary();
      digits.Add("CHU", 0);
      digits.Add("TEL", 1);
      digits.Add("OFT", 2);
      digits.Add("IVA", 3);
      digits.Add("EMY", 4);
      digits.Add("VNB", 5);
      digits.Add("POQ", 6);
      digits.Add("ERI", 7);
      digits.Add("CAD", 8);
      digits.Add("K-A", 9);
      digits.Add("IIA", 10);
      digits.Add("YLO", 11);
      digits.Add("PLA", 12);
      string input = Console.ReadLine();
      StringBuilder number = new StringBuilder();
      decimal output = 0;
      int power = input.Length / 3;
      for (int i = 0; i < input.Length; i += 3) {
        string digit = string.Format("{0}{1}{2}", input[i], input[i + 1], input[i + 2]);
        output += (decimal)(digits[digit] * Math.Pow(13, power - 1));
        power--;
      }
      Console.WriteLine(output);
    }
  }
}
Categories
Visual C# Телерик

Решение на задача – Moving Letters

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MovingLetters {
  class Program {
    static void Main() {
      string message = Console.ReadLine();
      List wordsList = new List(message.Split(' '));
      int lettersCount = wordsList.Sum(x => x.Length);
      int maxLetters = wordsList.Max(x => x.Length);
      StringBuilder sb = new StringBuilder();
      for (int i = 0; i < maxLetters; i++) {
        for (int j = 0; j < wordsList.Count; j++) {
          if (i < wordsList[j].Length) {
            sb.Append(wordsList[j][wordsList[j].Length - i - 1]);
          }
        }
      }
      int wordLettersCount = sb.Length;
      for (int i = 0; i < wordLettersCount; i++) {
        char letter = sb[i];
        sb.Remove(i, 1);
        int alphabetIndex = (letter < 97 ? letter - 64 : letter - 96);
        int wordIndex = i;
        while (alphabetIndex > 0) {
          wordIndex++;
          if (wordIndex == wordLettersCount) {
            wordIndex = 0;
          }
          alphabetIndex--;
        }
        sb.Insert(wordIndex, letter);
      }
      Console.WriteLine(sb.ToString());
    }
  }
}
Categories
Visual C# Телерик

Решение на задача – Encode and Encrypt

using System;
using System.Text;

namespace EncodeAndEncrypt {
  class Program {
    static void Main() {
      string message = Console.ReadLine();
      string cypher = Console.ReadLine();
      Console.WriteLine(Encode(Encrypt(message, cypher) + cypher) + cypher.Length);
    }

    static string Encrypt(string message, string cypher) {
      char[] cypherText = new char[message.Length];
      int index = 0;
      if (cypher.Length < message.Length) {
        for (int i = 0; i < message.Length; i++) {
          if (index == cypher.Length) {
            index = 0;
          }
          cypherText[i] = (char)((FindLetterIndex((message[i])) ^ FindLetterIndex(cypher[index])) + 65);
          index++;
        }
      } else {
        for (int i = 0; i < cypher.Length; i++) {
          if (index == message.Length) {
            index = 0;
          }
          if (i >= message.Length) {
            cypherText[index] = (char)((FindLetterIndex((cypherText[index])) ^ FindLetterIndex(cypher[i])) + 65);
          } else {
            cypherText[index] = (char)((FindLetterIndex((message[index])) ^ FindLetterIndex(cypher[i])) + 65);
          }
          index++;
        }
      }
      string encryptedText = string.Join(string.Empty, cypherText);
      return encryptedText;
    }

    static string Encode(string message) {
      string letters = string.Format("{0}*", message);
      char currentLetter = letters[0];
      int count = 1;
      StringBuilder sb = new StringBuilder();
      for (int i = 1; i < letters.Length; i++) {
        if (letters[i] == currentLetter) {
          count++;
        } else {
          switch (count) {
          case 1:
            sb.Append(currentLetter);
            break;
          case 2:
            sb.Append(currentLetter);
            sb.Append(currentLetter);
            break;
          default:
            sb.Append(count);
            sb.Append(currentLetter);
            break;
          }
          currentLetter = letters[i];
          count = 1;
        }
      }
      return sb.ToString();
    }
    static int FindLetterIndex(char letter) {
      int index = (letter < 97 ? letter - 64 : letter - 96) - 1;
      return index;
    }
  }
}
Categories
Visual C#

Програма за афинна трансформация

Програмата Афинна трансформация служи за трансформиране на XY координати от една координатна система в друга чрез афинна трансформация.

Програмата е тествана на Windows XP SP3 32bit.

Изисквания:

NET Framework 4.0

Връзка за сваляне:

Примерен входен файл:

1 92352.439 20359.231 84778.635 26014.364
2 84759.620 17042.702 85622.843 17771.625
3 88697.044 17379.409 86502.430 21624.425
4 85000.000 18000.000 84784.346 18292.392
5 87829.343 17421.001 86199.260 20810.372
6 87447.424 18177.309
Categories
Visual C#

Програма за Хелмертова трансформация

Програмата Хелмертова трансформация служи за трансформиране на XY координати чрез 4-параметрова Хелмертова трансформация, включваща две транслации, една ротация и мащабиране.

Изисквания:

Програмата изисква .Net Framework 4.0

Тествана е на Windows XP SP3 32bit

Връзка за сваляне:

Примерен входен файл за програмата:

1 92352.439 20359.231 84778.635 26014.364
2 84759.620 17042.702 85622.843 17771.625
3 88697.044 17379.409 86502.430 21624.425
4 85000.000 18000.000 84784.346 18292.392
5 87829.343 17421.001 86199.260 20810.372
6 87447.424 18177.30