using System.Collections.Generic;
internal class TaskSolver
public static void Main(string[] args)
TestGenerateWordsFromWord();
TestGetPreviousMaxDigital();
TestSearchQueenOrHorse();
Console.WriteLine("All Test completed!");
public static List<string> GenerateWordsFromWord(string word, List<string> wordDictionary)
string[] words = new string[15000];
Console.WriteLine("Сейчас мы посмотрим, сколько слов у тебя получиться составить из букв исходного!");
Console.Write("Введи исходное слово: ");
keyWord = Console.ReadLine();
while (keyWord.Length <= 2 || keyWord.Length > 15);
Console.WriteLine("\nХорошо, а теперь введи слова, которые ты можешь составить!");
for (int i = 0; ; i++, wIndex++, nIndex++)
char[] charsK = keyWord.ToCharArray();
Console.Write($"Введи слово {nIndex} или нажми 'Enter' для продолжения:");
words[i] = Console.ReadLine();
for (int n = 0; n < i; n++)
if (words[i] == words[n])
string chekWord = words[i];
char[] charsW = chekWord.ToCharArray();
for (int j = 0; j < charsW.Length; j++)
for (int k = 0; k < charsK.Length; k++)
if (charsW[j] == charsK[k])
if (charsW[j] < charsW.Length)
if (j == charsW.Length - 1 && k == charsK.Length - 1)
for (int m = 0; m < charsW.Length; m++)
string[] words2 = new string[wIndex];
for (int i = 0; i < wIndex; i++)
Console.WriteLine("Вот все подходящие слова, отсортированные в алфавитном порядке:");
for (int i = 0; i < words2.Length; i++)
Console.Write(words2[i] + "\t");
return new List<string>();
public static int MaxLengthTwoChar(string word)
Console.WriteLine("Сейчас мы приступим к Заданию 2: Два уникальных символа.");
char[] charL = new char[26];
Console.WriteLine("Введи строку длиной 1~1000, состоящий из a~z");
str = Console.ReadLine();
charS = str.ToCharArray();
for (int i = 0; i < charS.Length; i++)
if (charS[i] >= 'a' && charS[i] <= 'z' && charS.Length >= 1 && charS.Length <= 1000)
for (int i = 0; i < charS.Length; i++)
charL[Lindex] = charS[i];
for (int k = 0; k < i; k++)
if (charS[i] == charS[k])
if (k == i - 1 && charS[i] != charS[k])
charL[Lindex] = charS[i];
for (int i = 0; i < Lindex - 1; i++)
for (int j = i + 1; j < Lindex; j++)
for (int k = 0; k < charS.Length; k++)
if (charS[k] == charL[i] || charS[k] == charL[j])
NewStr += charS[k].ToString();
if (k == charS.Length - 1)
for (int m = 1; m < NewStr.Length; m++)
if (NewStr[m] == NewStr[m - 1])
if (NewStr.Length > maxNewL)
Console.Write("Длина самой длинной стрки: ");
Console.WriteLine(maxNewL);
public static long GetPreviousMaxDigital(long value)
Console.WriteLine("Сейчас мы приступим к Заданию 3: Предыдущее число\n");
Console.WriteLine("Введи число от 0 до 1*10^12:");
Str = Console.ReadLine();
isNumber = long.TryParse(Str, out Num);
if (Num == 0 && Str != "0")
while (Num < 0 || Num > 1000000000000);
charNum = sNum.ToCharArray();
PosIndex = charNum.Length - 1;
charNumNew = new char[charNum.Length];
while (charNum[PosIndex] < charNum[PosIndex + 1]);
for (long i = 0; i < PosIndex; i++)
charNumNew[i] = charNum[i];
PosIndex2 = PosIndex + 1;
if ((PosIndex2 < charNum.Length - 1) && (PosIndex2 != 0))
if (PosIndex2 == charNum.Length - 1)
while (charNum[PosIndex] > charNum[PosIndex2]);
charNumNew[PosIndex] = charNum[PosIndex2 - 1];
if (PosIndex2 < charNum.Length)
for (int i = 0; i < charNum.Length - PosIndex2; i++)
charNumNew[PosIndex + 1 + i] = charNum[charNum.Length - 1 - i];
if (i == charNum.Length - 1 - PosIndex2)
charNumNew[PosIndex + 2 + i] = charNum[PosIndex];
charNumNew[PosIndex + 1] = charNum[PosIndex];
SpaceIndex = PosIndex2 - PosIndex;
for (int i = 0; i < SpaceIndex - 2; i++)
charNumNew[charNum.Length - SpaceIndex + 2 + i] = charNum[PosIndex2 - 2 - i];
if (charNumNew[0] == '0')
charNumNew = new char[2] { '-', '1' };
else if (PosIndex2 >= charNum.Length - 1)
charNumNew[PosIndex] = charNum[PosIndex2];
charNumNew[PosIndex2] = charNum[PosIndex];
charNumNew = new char[2] { '-', '1' };
charNumNew = new char[2] { '-', '1' };
Console.WriteLine(charNumNew);
public static List<int> SearchQueenOrHorse(char[][] gridMap)
return new List<int> { -1, -1 };
public static long CalculateMaxCoins(int[][] mapData, int idStart, int idFinish)
private static void TestGenerateWordsFromWord()
var wordsList = new List<string>
"кот", "ток", "око", "мимо", "гром", "ром", "мама",
"рог", "морг", "огр", "мор", "порог", "бра", "раб", "зубр"
AssertSequenceEqual(GenerateWordsFromWord("арбуз", wordsList), new[] { "бра", "зубр", "раб" });
AssertSequenceEqual(GenerateWordsFromWord("лист", wordsList), new List<string>());
AssertSequenceEqual(GenerateWordsFromWord("маг", wordsList), new List<string>());
AssertSequenceEqual(GenerateWordsFromWord("погром", wordsList), new List<string> { "гром", "мор", "морг", "огр", "порог", "рог", "ром" });
private static void TestMaxLengthTwoChar()
AssertEqual(MaxLengthTwoChar("beabeeab"), 5);
AssertEqual(MaxLengthTwoChar("а"), 0);
AssertEqual(MaxLengthTwoChar("ab"), 2);
private static void TestGetPreviousMaxDigital()
AssertEqual(GetPreviousMaxDigital(21), 12l);
AssertEqual(GetPreviousMaxDigital(531), 513l);
AssertEqual(GetPreviousMaxDigital(1027), -1l);
AssertEqual(GetPreviousMaxDigital(2071), 2017l);
AssertEqual(GetPreviousMaxDigital(207034), 204730l);
AssertEqual(GetPreviousMaxDigital(135), -1l);
private static void TestSearchQueenOrHorse()
new[] {'s', '#', '#', '#', '#', '#'},
new[] {'#', 'x', 'x', 'x', 'x', '#'},
new[] {'#', '#', '#', '#', 'x', '#'},
new[] {'#', '#', '#', '#', 'x', '#'},
new[] {'#', '#', '#', '#', '#', 'e'},
AssertSequenceEqual(SearchQueenOrHorse(gridA), new[] { 3, 2 });
new[] {'s', '#', '#', '#', '#', 'x'},
new[] {'#', 'x', 'x', 'x', 'x', '#'},
new[] {'#', 'x', '#', '#', 'x', '#'},
new[] {'#', '#', '#', '#', 'x', '#'},
new[] {'x', '#', '#', '#', '#', 'e'},
AssertSequenceEqual(SearchQueenOrHorse(gridB), new[] { -1, 3 });
new[] {'s', '#', '#', '#', '#', 'x'},
new[] {'x', 'x', 'x', 'x', 'x', 'x'},
new[] {'#', '#', '#', '#', 'x', '#'},
new[] {'#', '#', '#', 'e', 'x', '#'},
new[] {'x', '#', '#', '#', '#', '#'},
AssertSequenceEqual(SearchQueenOrHorse(gridC), new[] { 2, -1 });
AssertSequenceEqual(SearchQueenOrHorse(gridD), new[] { -1, 1 });
AssertSequenceEqual(SearchQueenOrHorse(gridE), new[] { 1, -1 });
new[] {'x', '#', '#', 'x'},
new[] {'#', 'x', 'x', '#'},
new[] {'#', 'x', '#', 'x'},
new[] {'e', 'x', 'x', 's'},
new[] {'#', 'x', 'x', '#'},
new[] {'x', '#', '#', 'x'},
AssertSequenceEqual(SearchQueenOrHorse(gridF), new[] { -1, 5 });
private static void TestCalculateMaxCoins()
AssertEqual(CalculateMaxCoins(mapA, 0, 3), 11l);
AssertEqual(CalculateMaxCoins(mapB, 0, 5), -1l);
AssertEqual(CalculateMaxCoins(mapC, 0, 5), 19l);
private static void Assert(bool value)
throw new Exception("Assertion failed");
private static void AssertEqual(object value, object expectedValue)
if (value.Equals(expectedValue))
throw new Exception($"Assertion failed expected = {expectedValue} actual = {value}");
private static void AssertSequenceEqual<T>(IEnumerable<T> value, IEnumerable<T> expectedValue)
if (ReferenceEquals(value, expectedValue))
throw new ArgumentNullException(nameof(value));
if (expectedValue is null)
throw new ArgumentNullException(nameof(expectedValue));
var valueList = value.ToList();
var expectedValueList = expectedValue.ToList();
if (valueList.Count != expectedValueList.Count)
throw new Exception($"Assertion failed expected count = {expectedValueList.Count} actual count = {valueList.Count}");
for (var i = 0; i < valueList.Count; i++)
if (!valueList[i].Equals(expectedValueList[i]))
throw new Exception($"Assertion failed expected value at {i} = {expectedValueList[i]} actual = {valueList[i]}");