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;
}
}
}
Категория: Visual C#
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);
}
}
}
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);
}
}
}
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());
}
}
}
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
Програма за афинна трансформация
Програмата Афинна трансформация служи за трансформиране на 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
Програма за Хелмертова трансформация
Програмата Хелмертова трансформация служи за трансформиране на 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
Решение
using System;
namespace NightmareOnCodeStreet {
class Program {
static void Main() {
string number = Console.ReadLine();
char[] numbersList = number.ToCharArray();
int size = numbersList.Length;
if (numbersList[0] - '0' < 0) {
for (int i = 0; i < numbersList.Length - 1; i++) {
numbersList[i] = numbersList[i + 1];
}
size--;
}
int counter = 0;
int sum = 0;
for (int i = 0; i < size; i++) {
if (i % 2 != 0) {
if (Char.IsDigit(numbersList[i])) {
counter++;
sum += (int)(numbersList[i] - '0');
}
}
}
Console.WriteLine("{0} {1}", counter, sum);
}
}
}
Решение
using System;
namespace KaspichaniaBoats {
class Program {
static void Main() {
int n = int.Parse(Console.ReadLine());
int boatWidth = 2 * n + 1;
int dots = 1;
for (int i = 0; i < n; i++) {
Console.Write(new string('.', n - i));
if (i == 0) {
Console.Write(new string('*', 1));
} else if (i == 1) {
Console.Write(new string('*', 3));
} else {
Console.Write("*");
Console.Write(new string('.', dots));
Console.Write("*");
Console.Write(new string('.', dots));
Console.Write("*");
dots++;
}
Console.Write(new string('.', n - i));
Console.WriteLine();
}
Console.WriteLine(new string('*', boatWidth));
int counter = 1;
dots = n - 2;
for (int i = 1; i <= n / 2; i++) {
Console.Write(new string('.', i));
Console.Write(new string('*', 1));
Console.Write(new string('.', dots));
Console.Write(new string('*', 1));
Console.Write(new string('.', dots));
Console.Write(new string('*', 1));
Console.Write(new string('.', i));
dots--;
counter++;
Console.WriteLine();
}
Console.Write(new string('.', counter));
Console.Write(new string('*', boatWidth - 2 * counter));
Console.Write(new string('.', counter));
}
}
}
Решение
using System;
namespace _2_4_8 {
class Program {
static void Main() {
decimal a = decimal.Parse(Console.ReadLine());
decimal b = decimal.Parse(Console.ReadLine());
decimal c = decimal.Parse(Console.ReadLine());
decimal r = 0;
switch ((int) b) {
case 2:
r = a % c;
break;
case 4:
r = a + c;
break;
case 8:
r = a * c;
break;
}
int remainder = r % 4;
if (remainder == 0) {
Console.WriteLine(r / 4);
} else {
Console.WriteLine(remainder);
}
Console.WriteLine(r);
}
}
}