diff --git a/CourseApp.Tests/Module2/BubbleSortPairTest.cs b/CourseApp.Tests/Module2/BubbleSortPairTest.cs new file mode 100644 index 0000000..7f4c9b8 --- /dev/null +++ b/CourseApp.Tests/Module2/BubbleSortPairTest.cs @@ -0,0 +1,60 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class BubbleSortPairTest : IDisposable + { + private const string Inp1 = @"3 +101 80 +305 90 +200 14"; + + private const string Out1 = @"305 90 +101 80 +200 14"; + + private const string Inp2 = @"3 +20 80 +30 90 +25 90"; + + private const string Out2 = @"25 90 +30 90 +20 80"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + [InlineData(Inp2, Out2)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + Bubble_Sort_Pair.Bubble_Sort_Method(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module2/BubbleSortTest.cs b/CourseApp.Tests/Module2/BubbleSortTest.cs index 8a9b192..82f9080 100644 --- a/CourseApp.Tests/Module2/BubbleSortTest.cs +++ b/CourseApp.Tests/Module2/BubbleSortTest.cs @@ -1,18 +1,28 @@ -using System; -using System.IO; -using Xunit; -using CourseApp.Module2; - -namespace CourseApp.Tests.Module2 +namespace CourseApp.Tests.Module2 { + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + [Collection("Sequential")] public class BubbleSortTest : IDisposable { - private const string Inp1 = @"7 -5 1 7 3 9 4 1"; + private const string Inp1 = @"4 +4 3 2 1"; + + private const string Out1 = @"3 4 2 1 +3 2 4 1 +3 2 1 4 +2 3 1 4 +2 1 3 4 +1 2 3 4"; - private const string Inp2 = @"3 --10 7 2"; + private const string Inp2 = @"4 +1 2 3 4"; + + private const string Out2 = @"0"; public void Dispose() { @@ -24,8 +34,8 @@ public void Dispose() } [Theory] - [InlineData(Inp1, "1 1 3 4 5 7 9")] - [InlineData(Inp2, "-10 2 7")] + [InlineData(Inp1, Out1)] + [InlineData(Inp2, Out2)] public void Test1(string input, string expected) { var stringWriter = new StringWriter(); @@ -35,11 +45,13 @@ public void Test1(string input, string expected) Console.SetIn(stringReader); // act - BubbleSort.BubbleSortMethod(); + Bubble_Sort.Bubble_Sort_Method(); // assert var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); - Assert.Equal($"{expected}", output[0]); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); } } -} +} \ No newline at end of file diff --git a/CourseApp.Tests/Module2/InversionSortTest.cs b/CourseApp.Tests/Module2/InversionSortTest.cs new file mode 100644 index 0000000..b343705 --- /dev/null +++ b/CourseApp.Tests/Module2/InversionSortTest.cs @@ -0,0 +1,52 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class InversionSortTest : IDisposable + { + private const string Inp1 = @"1 +1"; + + private const string Out1 = @"0"; + + private const string Inp2 = @"5 +5 4 3 2 1"; + + private const string Out2 = @"10"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + [InlineData(Inp2, Out2)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + Inversion_Sort.Start(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module2/MergeSortTest.cs b/CourseApp.Tests/Module2/MergeSortTest.cs new file mode 100644 index 0000000..c0370c2 --- /dev/null +++ b/CourseApp.Tests/Module2/MergeSortTest.cs @@ -0,0 +1,63 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class MergeSortTest : IDisposable + { + private const string Inp1 = @"1 +1"; + + private const string Out1 = @"1"; + + private const string Inp2 = @"2 +3 1"; + + private const string Out2 = @"1 2 1 3 +1 3"; + + private const string Inp3 = @"5 +5 4 3 2 1"; + + private const string Out3 = @"1 2 4 5 +4 5 1 2 +3 5 1 3 +1 5 1 5 +1 2 3 4 5"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + [InlineData(Inp2, Out2)] + [InlineData(Inp3, Out3)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + Merge_Sort.Enter(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module2/NumbDiffTest.cs b/CourseApp.Tests/Module2/NumbDiffTest.cs new file mode 100644 index 0000000..e1ee262 --- /dev/null +++ b/CourseApp.Tests/Module2/NumbDiffTest.cs @@ -0,0 +1,46 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class NumbDiffTest : IDisposable + { + private const string Inp1 = @"5 +1 0 1 2 0"; + + private const string Out1 = @"3"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + Numb_Diff.Count_Diff_Method(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module2/RadixSortTest.cs b/CourseApp.Tests/Module2/RadixSortTest.cs new file mode 100644 index 0000000..763c9f9 --- /dev/null +++ b/CourseApp.Tests/Module2/RadixSortTest.cs @@ -0,0 +1,82 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class RadixSortTest : IDisposable + { + private const string Inp1 = @"9 +12 +32 +45 +67 +98 +29 +61 +35 +09"; + + private const string Out1 = @"Initial array: +12, 32, 45, 67, 98, 29, 61, 35, 09 +********** +Phase 1 +Bucket 0: empty +Bucket 1: 61 +Bucket 2: 12, 32 +Bucket 3: empty +Bucket 4: empty +Bucket 5: 45, 35 +Bucket 6: empty +Bucket 7: 67 +Bucket 8: 98 +Bucket 9: 29, 09 +********** +Phase 2 +Bucket 0: 09 +Bucket 1: 12 +Bucket 2: 29 +Bucket 3: 32, 35 +Bucket 4: 45 +Bucket 5: empty +Bucket 6: 61, 67 +Bucket 7: empty +Bucket 8: empty +Bucket 9: 98 +********** +Sorted array: +09, 12, 29, 32, 35, 45, 61, 67, 98"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + Radix_Sort.Start(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module2/WarehouseTest.cs b/CourseApp.Tests/Module2/WarehouseTest.cs new file mode 100644 index 0000000..5302551 --- /dev/null +++ b/CourseApp.Tests/Module2/WarehouseTest.cs @@ -0,0 +1,52 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class WarehouseTest : IDisposable + { + private const string Inp1 = @"5 +1 50 3 4 3 +16 +1 2 3 4 5 1 3 3 4 5 5 5 5 5 4 5"; + + private const string Out1 = @"yes +no +no +no +yes"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + Warehouse.Input_Values(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module3/CycleSDVGTest b/CourseApp.Tests/Module3/CycleSDVGTest new file mode 100644 index 0000000..af80a03 --- /dev/null +++ b/CourseApp.Tests/Module3/CycleSDVGTest @@ -0,0 +1,44 @@ +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; + + [Collection("Sequential")] + public class CircularStrTest : IDisposable + { + private const string Inp1 = @"z"; + + private const string Out1 = @"1"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + CircularStr.EnterVal(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module3/CycleSTRTest b/CourseApp.Tests/Module3/CycleSTRTest new file mode 100644 index 0000000..b6daba3 --- /dev/null +++ b/CourseApp.Tests/Module3/CycleSTRTest @@ -0,0 +1,44 @@ +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; + + [Collection("Sequential")] + public class CircularStrTest : IDisposable + { + private const string Inp1 = @"z"; + + private const string Out1 = @"1"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + CircularStr.EnterVal(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} diff --git a/CourseApp.Tests/Module3/PeriodSTRTest b/CourseApp.Tests/Module3/PeriodSTRTest new file mode 100644 index 0000000..d0d1048 --- /dev/null +++ b/CourseApp.Tests/Module3/PeriodSTRTest @@ -0,0 +1,54 @@ +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; + + [Collection("Sequential")] + public class PeriodStrTest : IDisposable + { + private const string Inp1 = @"aaaaa"; + + private const string Out1 = @"5"; + + private const string Inp2 = @"abcabcabc"; + + private const string Out2 = @"3"; + + private const string Inp3 = @"abab"; + + private const string Out3 = @"2"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + [InlineData(Inp2, Out2)] + [InlineData(Inp3, Out3)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + PeriodStr.EnterVal(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module3/TaskFindTest b/CourseApp.Tests/Module3/TaskFindTest new file mode 100644 index 0000000..2bb45c0 --- /dev/null +++ b/CourseApp.Tests/Module3/TaskFindTest @@ -0,0 +1,47 @@ +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; + + [Collection("Sequential")] + public class FindSubstrTest : IDisposable + { + private const string Inp1 = @"ababbababa +aba"; + + private const string Out1 = @"0 5 7 "; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + FindSubstr.EnterValues(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} +FindSubstrTest.cs +2 кб \ No newline at end of file diff --git a/CourseApp.Tests/Module4/ClosmallTest b/CourseApp.Tests/Module4/ClosmallTest new file mode 100644 index 0000000..3626b44 --- /dev/null +++ b/CourseApp.Tests/Module4/ClosmallTest @@ -0,0 +1,45 @@ +namespace CourseApp.Tests.Module4 +{ + using System; + using System.IO; + using CourseApp.Module4; + using Xunit; + + [Collection("Sequential")] + public class NearSmalTest : IDisposable + { + private const string Inp1 = @"10 +1 2 3 2 1 4 2 5 3 1"; + + private const string Out1 = @"-1 4 3 4 -1 6 9 8 9 -1 "; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + NearSmal.GetNearestSmaller(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module4/GetPSPTest b/CourseApp.Tests/Module4/GetPSPTest new file mode 100644 index 0000000..9fe4257 --- /dev/null +++ b/CourseApp.Tests/Module4/GetPSPTest @@ -0,0 +1,49 @@ +namespace CourseApp.Tests.Module4 +{ + using System; + using System.IO; + using CourseApp.Module4; + using Xunit; + + [Collection("Sequential")] + public class PspTest : IDisposable + { + private const string Inp1 = @"())(()"; + + private const string Out1 = @"2"; + + private const string Inp2 = @"))((("; + + private const string Out2 = @"5"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + [InlineData(Inp2, Out2)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + Psp.GetPsp(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module4/MinOtrTest b/CourseApp.Tests/Module4/MinOtrTest new file mode 100644 index 0000000..337b380 --- /dev/null +++ b/CourseApp.Tests/Module4/MinOtrTest @@ -0,0 +1,49 @@ +namespace CourseApp.Tests.Module4 +{ + using System; + using System.IO; + using CourseApp.Module4; + using Xunit; + + [Collection("Sequential")] + public class MinSegTest : IDisposable + { + private const string Inp1 = @"7 3 +1 3 2 4 5 3 1"; + + private const string Out1 = @"1 +2 +2 +3 +1"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + MinSeg.GetMinSeg(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module4/sortttest b/CourseApp.Tests/Module4/sortttest new file mode 100644 index 0000000..74589fc --- /dev/null +++ b/CourseApp.Tests/Module4/sortttest @@ -0,0 +1,795 @@ +DisL0V3 +#7013 + + + +Текстовый канал +general-chat +Поиск + +Добро пожаловать на канал #general-chat! +Это начало канала #general-chat. +20 октября 2021 г. +Рады тебя видеть, +m.rau +. + — 20.10.2021 + +Помашите и поздоровайтесь! + +markkket — 20.10.2021 +Hello +21 октября 2021 г. +Дарина Кочнева 1/42 + уже с нами! + — 21.10.2021 + +Помашите и поздоровайтесь! +26 октября 2021 г. + +m.rau — 26.10.2021 +я чуть с обычным англом не перепутала +14 ноября 2021 г. + +markkket — 14.11.2021 +https://www.audacityteam.org/ +Audacity ® +James Crook +Home +Welcome to Audacity + + +Audacity® is free, open source, cross-platform audio software for multi-track recording and editing. + +Audacity is available for Windows®, Mac®, GNU/Linux® and other operating systems. Check our feature list, Wiki and Forum. + + + +Download Audacity 2.1.3 + + + +Mar 17th, 2017: Audacity +22 февраля 2022 г. +Dmitry_Shi*** + присоединяется к вашей пати. + — 22.02.2022 + + +Помашите и поздоровайтесь! +maks + проскальзывает на сервер. + — 22.02.2022 + +Помашите и поздоровайтесь! +5 марта 2022 г. +Рады тебя видеть, +DisL0V3 +. + — 05.03.2022 + +Помашите и поздоровайтесь! +9 марта 2022 г. + +markkket — 09.03.2022 +у меня с ноута звука нет позвоню в вк +27 марта 2022 г. +poulina + уже здесь. + — 27.03.2022 + +Помашите и поздоровайтесь! +23 апреля 2022 г. +Добро пожаловать, +Lis +. Надеемся, ты к нам не без пиццы! + — 23.04.2022 + +Помашите и поздоровайтесь! +24 апреля 2022 г. +Pavelqsw + запрыгивает на сервер. + — 24.04.2022 + +Помашите и поздоровайтесь! +28 мая 2022 г. + +DisL0V3 — 28.05.2022 + +3 июня 2022 г. + +Lis — Сегодня, в 13:19 +это 3 модуль +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +Раскрыть +Class1.cs +2 кб +using System; +using System.Linq; + +namespace CourseApp.Module3 +{ + public class Program +Раскрыть +Class2.cs +2 кб +using System; + +namespace CourseApp.Module3 +{ + public class Program + { +Раскрыть +Class3.cs +2 кб +using System; + +namespace CourseApp.Module3 +{ + public class Program + { +Раскрыть +Class4.cs +1 кб +[13:19] +это 4 модуль +using System; + +namespace CourseApp.Module4 +{ + public class Psp + { +Раскрыть +Class1.cs +2 кб +using System; + +namespace CourseApp.Module4 +{ + public class SORT + { +Раскрыть +Class2.cs +3 кб +using System; + +public class NearSmal +{ + public static void Main() + { +Раскрыть +Class3.cs +2 кб +using System; + +public class MinSeg +{ + public static void Main() + { +Раскрыть +Class4.cs +4 кб +[13:19] +5 модуль +using System; +using System.Collections.Generic; + +namespace Programm +{ + public class BinarTree +Раскрыть +Class1.cs +3 кб +using System; +using System.Collections.Generic; + +namespace Programm +{ + public class IsTreeBalanced +Раскрыть +Class2.cs +3 кб +[13:19] +то что с верху это контест +[13:21] +это 3 модуль гит +using System; + +namespace CourseApp.Module3 +{ + public class CircularStr + { + public static int[] Prefix_function(string b) + { + int[] res = new int[b.Length]; + res[0] = 0; + + for (int i = 0; i < b.Length - 1; i++) + { + int j = res[i]; + + while (j > 0 && b[i + 1] != b[j]) + { + j = res[j - 1]; + } + + if (b[i + 1] == b[j]) + { + res[i + 1] = j + 1; + } + else + { + res[i + 1] = 0; + } + } + + return res; + } + + public static void EnterVal() + { + string b = Console.ReadLine(); + + int[] prefixs = Prefix_function(b); + + int result = b.Length - prefixs[b.Length - 1]; + + Console.WriteLine(result); + } + } +} +Свернуть +CircularStr.cs +1 кб +using System; +using System.Linq; + +namespace CourseApp.Module3 +{ + public class CyclicShift +Раскрыть +CyclicShift.cs +2 кб +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +Раскрыть +FindSubstr.cs +2 кб +using System; + +namespace CourseApp.Module3 +{ + public class PeriodStr + { +Раскрыть +PeriodStr.cs +2 кб +[13:21] +это 4 модуль гит +using System; + +public class MinSeg +{ + public static void GetMinSeg() + { +Раскрыть +MinSeg.cs +4 кб +using System; + +public class NearSmal +{ + public static void GetNearestSmaller() + { +Раскрыть +NearSmal.cs +2 кб +using System; + +namespace CourseApp.Module4 +{ + public class Psp + { +Раскрыть +Psp.cs +2 кб +using System; + +namespace CourseApp.Module4 +{ + public class SORT + { +Раскрыть +SORT.cs +3 кб +[13:23] +это 5 модуль гит +using System; +using System.Collections.Generic; + +namespace CourseApp.Module5.Task_1 +{ + public class BinarTreeBranch + { + private Node root; + private List size; + + public static void BinaryTreeBranchMethod() + { + string s = Console.ReadLine(); + + string[] sValues = s.Split(' '); + + var tree = new BinarTreeBranch(); + + for (int i = 0; i < sValues.Length - 1; i++) + { + tree.Insert(int.Parse(sValues[i])); + } + + tree.FindLastElem(); + } + + public void Insert(int n) + { + root = InnerInsert(n, root); + } + + public List GetValues() + { + size = new List(); + InnerTraversal(root); + return size; + } + + private bool InnerFind(int n, Node root) + { + if (root == null) + { + return false; + } + + if (n == root.Data) + { + return true; + } + else if (n < root.Data) + { + return InnerFind(n, root.Left); + } + else + { + return InnerFind(n, root.Right); + } + } + + public static void BinaryTreeMethod() + { + throw new NotImplementedException(); + } + + private bool Find(int n) + { + return InnerFind(n, root); + } + + private void FindLastElem() + { + LastElem(root); + } + + private void LastElem(Node value) + { + if (value == null) + { + return; + } + + LastElem(value.Left); + + if ((value.Left != null && value.Right == null) || (value.Right != null && value.Left == null)) + { + Console.WriteLine(value.Data); + } + + LastElem(value.Right); + } + + private Node InnerInsert(int n, Node root) + { + if (root == null) + { + return new Node(n); + } + + if (root.Data > n) + { +... (осталось: 39 строк) +Свернуть +BinarTreeBranch.cs +4 кб +using System; +using System.Collections.Generic; + +namespace CourseApp.Module5.Task_1 +{ + public class IsTreeBalanced + { + private Node root; + + public static void IsTreeBalancedMethod() + { + string s = Console.ReadLine(); + + string[] values = s.Split(' '); + + var tree = new IsTreeBalanced(); + + for (int i = 0; i < values.Length - 1; i++) + { + tree.Insert(int.Parse(values[i])); + } + + if (tree.IsBalanced(tree.root)) + { + Console.WriteLine("YES"); + } + else + { + Console.WriteLine("NO"); + } + } + + public void Insert(int data) + { + root = InnerInsert(data, root); + } + + private Node InnerInsert(int data, Node root) + { + if (root == null) + { + return new Node(data); + } + + if (root.Data > data) + { + root.Left = InnerInsert(data, root.Left); + } + else if (root.Data < data) + { + root.Right = InnerInsert(data, root.Right); + } + + return root; + } + + private bool IsBalanced(Node node) + { + int lh; + + int rh; + + if (node == null) + { + return true; + } + + lh = Height(node.Left); + rh = Height(node.Right); + + if (Math.Abs(lh - rh) <= 1 && IsBalanced(node.Left) + && IsBalanced(node.Right)) + { + return true; + } + + return false; + } + + private int Height(Node node) + { + if (node == null) + { + return 0; + } + + return 1 + Math.Max(Height(node.Left), Height(node.Right)); + } + } +} +Свернуть +IsTreeBalanced.cs +3 кб +namespace CourseApp.Module5.Task_1 +{ + public class Node + { + public Node(int data) + { + Data = data; + Left = null; + Right = null; + } + + public Node Left { get; set; } + + public Node Right { get; set; } + + public int Data { get; set; } + } +} +Свернуть +Node.cs +1 кб + +DisL0V3 — Сегодня, в 13:37 +бля сек + +Lis — Сегодня, в 13:49 +тест 1 модуля +using System; +using System.IO; +using Xunit; +using CourseApp.Module1; + +namespace CourseApp.Tests.Module1 +Раскрыть +AplusBTest.cs +2 кб +[13:49] +тест 2 модуля +namespace CourseApp.Tests.Module2 +{ + using System; + using System.IO; + using CourseApp.Module2; + using Xunit; +Раскрыть +BubbleSortTest.cs +2 кб +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; +Раскрыть +InversionCountTest.cs +2 кб +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; +Раскрыть +MergeTest.cs +2 кб +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; +Раскрыть +NumberDifTest.cs +2 кб +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; +Раскрыть +PairSortTest.cs +2 кб +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; +Раскрыть +RadixSortTest.cs +2 кб +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; +Раскрыть +WarehouseTest.cs +2 кб +[13:50] +тест 3 модуля +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; +Раскрыть +CircularStrTest.cs +2 кб +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; +Раскрыть +CyclingShiftTest.cs +2 кб +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; +Раскрыть +FindSubstrTest.cs +2 кб +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; +Раскрыть +PeriodStrTest.cs +2 кб +[13:50] +тест 4 модуля +namespace CourseApp.Tests.Module4 +{ + using System; + using System.IO; + using CourseApp.Module4; + using Xunit; +Раскрыть +MinSegTest.cs +2 кб +namespace CourseApp.Tests.Module4 +{ + using System; + using System.IO; + using CourseApp.Module4; + using Xunit; +Раскрыть +NearSmalTest.cs +2 кб +namespace CourseApp.Tests.Module4 +{ + using System; + using System.IO; + using CourseApp.Module4; + using Xunit; +Раскрыть +PspTest.cs +2 кб +namespace CourseApp.Tests.Module4 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module4; +Раскрыть +SortTest.cs +2 кб +[13:50] +тест 5 модуля +namespace CourseApp.Tests.Module5 +{ + using System; + using System.IO; + using CourseApp.Module5; + using CourseApp.Module5.Task_1; +Раскрыть +BinarTreeBranchTest.cs +2 кб +namespace CourseApp.Tests.Module5 +{ + using System; + using System.IO; + using CourseApp.Module5; + using CourseApp.Module5.Task_1; +Раскрыть +IsTreeBalancedTest.cs +2 кб + +Написать #general-chat + + + + + +Осталось символов: 2000 + для выбора +В СЕТИ, 4 УЧАСТНИКАВ СЕТИ — 4 + +DisL0V3 + +Lis + +markkket + +poulina +НЕ В СЕТИ, 5 УЧАСТНИКОВНЕ В СЕТИ — 5 + +Dmitry_Shi*** + +m.rau + +maks + +Pavelqsw + +Дарина Кочнева 1/42 +namespace CourseApp.Tests.Module4 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module4; + using Xunit; + + [Collection("Sequential")] + public class SortTest : IDisposable + { + private const string Inp1 = @"3 +3 2 1"; + + private const string Out1 = @"YES"; + + private const string Inp2 = @"4 +4 1 3 2"; + + private const string Out2 = @"YES"; + + private const string Inp3 = @"3 +2 3 1"; + + private const string Out3 = @"NO"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + [InlineData(Inp2, Out2)] + [InlineData(Inp3, Out3)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + SORT.GetSorting(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module5/BaltreeTest b/CourseApp.Tests/Module5/BaltreeTest new file mode 100644 index 0000000..b42c0bb --- /dev/null +++ b/CourseApp.Tests/Module5/BaltreeTest @@ -0,0 +1,45 @@ +namespace CourseApp.Tests.Module5 +{ + using System; + using System.IO; + using CourseApp.Module5; + using CourseApp.Module5.Task_1; + using Xunit; + + [Collection("Sequential")] + public class IsTreeBalancedTest : IDisposable + { + private const string Inp1 = @"7 3 2 1 9 5 4 6 8 0"; + + private const string Out1 = @"YES"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + IsTreeBalanced.IsTreeBalancedMethod(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp.Tests/Module5/BranchTreeTest b/CourseApp.Tests/Module5/BranchTreeTest new file mode 100644 index 0000000..11c135f --- /dev/null +++ b/CourseApp.Tests/Module5/BranchTreeTest @@ -0,0 +1,46 @@ +namespace CourseApp.Tests.Module5 +{ + using System; + using System.IO; + using CourseApp.Module5; + using CourseApp.Module5.Task_1; + using Xunit; + + [Collection("Sequential")] + public class BinarTreeBranchTest : IDisposable + { + private const string Inp1 = @"7 3 2 1 9 5 4 6 8 0"; + + private const string Out1 = @"2 +9"; + + public void Dispose() + { + var standardOut = new StreamWriter(Console.OpenStandardOutput()); + standardOut.AutoFlush = true; + var standardIn = new StreamReader(Console.OpenStandardInput()); + Console.SetOut(standardOut); + Console.SetIn(standardIn); + } + + [Theory] + [InlineData(Inp1, Out1)] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + BinarTreeBranch.BinaryTreeMethod(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} \ No newline at end of file diff --git a/CourseApp/Module2/BubbleSort.cs b/CourseApp/Module2/BubbleSort.cs deleted file mode 100644 index cc49214..0000000 --- a/CourseApp/Module2/BubbleSort.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace CourseApp.Module2 -{ - public class BubbleSort - { - public static void BubbleSortMethod() - { - int n = int.Parse(Console.ReadLine()); - string s = Console.ReadLine(); - string[] sValues = s.Split(' '); - int[] arr = new int[n]; - for (int i = 0; i < n; i++) - { - arr[i] = int.Parse(sValues[i]); - } - - for (int i = 0; i < arr.Length - 1; i++) - { - for (int j = 0; j < arr.Length - i - 1; j++) - { - if (arr[j] > arr[j + 1]) - { - // int temp = arr[j]; - // arr[j] = arr[j + 1]; - // arr[j+1] = temp; - (arr[j], arr[j + 1]) = (arr[j + 1], arr[j]); - } - } - } - - string result = string.Join(" ", arr); - Console.WriteLine(result); - } - } -} diff --git a/CourseApp/Module2/Bubble_Sort.cs b/CourseApp/Module2/Bubble_Sort.cs new file mode 100644 index 0000000..aa7927f --- /dev/null +++ b/CourseApp/Module2/Bubble_Sort.cs @@ -0,0 +1,41 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CourseApp.Module2 +{ + public class Bubble_Sort + { + public static void Bubble_Sort_Method() + { + int n = int.Parse(Console.ReadLine()); + string s = Console.ReadLine(); + string[] sValues = s.Split(' '); + int[] array = new int[n]; + for (int i = 0; i < n; i++) + { + array[i] = int.Parse(sValues[i]); + } + + bool swap = false; + for (int i = 0; i < array.Length - 1; i++) + { + for (int j = 0; j < array.Length - i - 1; j++) + { + if (array[j] > array[j + 1]) + { + (array[j], array[j + 1]) = (array[j + 1], array[j]); + string result = string.Join(" ", array); + Console.WriteLine(result); + swap = true; + } + } + } + + if (swap == false) + { + Console.WriteLine(0); + } + } + } +} diff --git a/CourseApp/Module2/Bubble_Sort_Pair.cs b/CourseApp/Module2/Bubble_Sort_Pair.cs new file mode 100644 index 0000000..ea7b9fa --- /dev/null +++ b/CourseApp/Module2/Bubble_Sort_Pair.cs @@ -0,0 +1,42 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CourseApp.Module2 +{ + public class Bubble_Sort_Pair + { + public static void Bubble_Sort_Method() + { + int numberOfElements = int.Parse(Console.ReadLine()); + string[][] array = new string[numberOfElements][]; + string[] value = Console.ReadLine().Split(' '); + array[0] = value; + for (int i = 1; i < numberOfElements; i++) + { + string[] temp = Console.ReadLine().Split(' '); + array[i] = temp; + + for (int j = 0; j < i; j++) + { + if (int.Parse(array[j][1]) < int.Parse(array[i][1])) + { + (array[j], array[i]) = (array[i], array[j]); + } + else if (int.Parse(array[j][1]) == int.Parse(array[i][1])) + { + if (int.Parse(array[j][0]) > int.Parse(array[i][0])) + { + (array[j], array[i]) = (array[i], array[j]); + } + } + } + } + + for (int i = 0; i < numberOfElements; i++) + { + Console.WriteLine(array[i][0] + " " + array[i][1]); + } + } + } +} diff --git a/CourseApp/Module2/Inversion_Sort.cs b/CourseApp/Module2/Inversion_Sort.cs new file mode 100644 index 0000000..61d6908 --- /dev/null +++ b/CourseApp/Module2/Inversion_Sort.cs @@ -0,0 +1,82 @@ +using System; + +namespace CourseApp.Module2 +{ + public class Inversion_Sort + { + private static long inversionCount = 0; + + public static void Start() + { + int number = int.Parse(Console.ReadLine()); + if (number > 1) + { + string temp = Console.ReadLine(); + string[] values = temp.Split(' '); + int[] array = new int[number]; + for (int i = 0; i < values.Length; i++) + { + array[i] = int.Parse(values[i]); + } + + int[] result = Sort(array, 0, number); + Console.WriteLine(inversionCount); + } + else + { + Console.WriteLine(0); + } + } + + public static int[] Merge(int[] left, int[] right) + { + int i = 0; + int j = 0; + int[] result = new int[left.Length + right.Length]; + + for (int k = 0; k < result.Length; k++) + { + if (i == left.Length) + { + result[k] = right[j]; + j++; + } + else if (j == right.Length) + { + result[k] = left[i]; + i++; + } + else if (left[i] <= right[j]) + { + result[k] = left[i]; + i++; + } + else + { + result[k] = right[j]; + j++; + inversionCount += left.Length - i; + } + } + + return result; + } + + public static int[] Sort(int[] array, int firstIndex, int lastIndex) + { + if (lastIndex - firstIndex == 1) + { + int[] res = new int[1]; + res[0] = array[firstIndex]; + return res; + } + + int m = (firstIndex + lastIndex) / 2; + + int[] left = Sort(array, firstIndex, m); + int[] right = Sort(array, m, lastIndex); + + return Merge(left, right); + } + } +} \ No newline at end of file diff --git a/CourseApp/Module2/Merge_Sort.cs b/CourseApp/Module2/Merge_Sort.cs new file mode 100644 index 0000000..0d8ec8d --- /dev/null +++ b/CourseApp/Module2/Merge_Sort.cs @@ -0,0 +1,77 @@ +using System; + + +namespace CourseApp.Module2 +{ + public class Merge_Sort + { + public static int[] Merge(int[] a, int[] b) + { + int i = 0; + int j = 0; + int[] c = new int[a.Length + b.Length]; + for (int k = 0; k < c.Length; k++) + { + if (i == a.Length) + { + c[k] = b[j]; + j++; + } + else if (j == b.Length) + { + c[k] = a[i]; + i++; + } + else if (a[i] <= b[j]) + { + c[k] = a[i]; + i++; + } + else + { + c[k] = b[j]; + j++; + } + } + + return c; + } + + public static int[] MergeSort(int[] v, int left, int right) + { + if (right - left == 1) + { + int[] res = new int[1]; + res[0] = v[left]; + return res; + } + + int m = (left + right) / 2; + + int[] left_half = MergeSort(v, left, m); + int[] right_half = MergeSort(v, m, right); + + int[] sorting = Merge(left_half, right_half); + + Console.WriteLine("{0} {1} {2} {3}", left + 1, right, sorting[0], sorting[^1]); + + return Merge(left_half, right_half); + } + + public static void Enter() + { + int numbers = int.Parse(Console.ReadLine()); + string str = Console.ReadLine(); + string[] sValues = str.Split(' '); + int[] arr = new int[numbers]; + for (int i = 0; i < numbers; i++) + { + arr[i] = int.Parse(sValues[i]); + } + + int[] sorted_arr = MergeSort(arr, 0, numbers); + + Console.WriteLine("{0}", string.Join(" ", sorted_arr)); + } + } +} diff --git a/CourseApp/Module2/Numb_Diff.cs b/CourseApp/Module2/Numb_Diff.cs new file mode 100644 index 0000000..e0eb4f5 --- /dev/null +++ b/CourseApp/Module2/Numb_Diff.cs @@ -0,0 +1,77 @@ +using System; + +namespace CourseApp.Module2 +{ + public class Numb_Diff + { + public static void Count_Diff_Method() + { + int number = int.Parse(Console.ReadLine()); + string[] value = Console.ReadLine().Split(' '); + int[] array = new int[number]; + + for (int i = 0; i < number; ++i) + { + array[i] = int.Parse(value[i]); + } + + QuickSort(array, 0, number); + + int count = 0; + + for (int i = 1; i < number; i++) + { + if (array[i] != array[i - 1]) + { + count++; + } + } + + Console.Write(count + 1); + } + + public static int Partition(int[] array, int leftIndex, int rightIndex) + { + int i = leftIndex; + int j = rightIndex - 1; + int v = array[(leftIndex + rightIndex - 1) / 2]; + + while (i <= j) + { + while (array[i] < v) + { + i++; + } + + while (array[j] > v) + { + j--; + } + + if (i >= j) + { + break; + } + + (array[i], array[j]) = (array[j], array[i]); + i++; + j--; + } + + return j + 1; + } + + public static void QuickSort(int[] array, int leftIndex, int rightIndex) + { + if (rightIndex - leftIndex <= 1) + { + return; + } + + int q = Partition(array, leftIndex, rightIndex); + + QuickSort(array, leftIndex, q); + QuickSort(array, q, rightIndex); + } + } +} \ No newline at end of file diff --git a/CourseApp/Module2/Radix_Sort.cs b/CourseApp/Module2/Radix_Sort.cs new file mode 100644 index 0000000..bc19c36 --- /dev/null +++ b/CourseApp/Module2/Radix_Sort.cs @@ -0,0 +1,80 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CourseApp.Module2 +{ + public class Radix_Sort + { + + public static void RadixSort(string[] arr_string, ulong n) + { + int numb_phaze = 1; + int rank = arr_string[0].Length; + + Console.WriteLine("Initial array:"); + Console.WriteLine("{0}", string.Join(", ", arr_string)); + + foreach (var i in Enumerable.Range(0, Convert.ToInt32(Math.Ceiling(Convert.ToDouble(-1 - (rank - 1)) / -1))).Select(x_1 => rank - 1 + (x_1 * -1))) + { + Console.WriteLine("**********"); + Console.WriteLine("Phase {0}", numb_phaze); + ulong m; + List[] arrayList = new List[10]; + for (m = 0; m < 10; m++) + { + arrayList[m] = new List(); + } + + for (int j = 0; j < arr_string.Length; j++) + { + int k = int.Parse(arr_string[j].Substring(rank - numb_phaze, 1)); + arrayList[k].Add(arr_string[j]); + } + + for (m = 0; m < 10; m++) + { + if (arrayList[m].Count == 0) + { + Console.WriteLine("Bucket " + m + ": empty"); + } + else + { + Console.WriteLine("Bucket " + m + ": {0}", string.Join(", ", arrayList[m])); + } + } + + int l = 0; + + for (m = 0; m < 10; m++) + { + for (int j = 0; j < arrayList[m].Count; j++) + { + arr_string[l] = arrayList[m][j]; + l++; + } + } + + numb_phaze++; + } + + Console.WriteLine("**********"); + Console.WriteLine("Sorted array:"); + Console.Write("{0}", string.Join(", ", arr_string)); + } + + public static void Start() + { + ulong n = ulong.Parse(Console.ReadLine()); + string[] arr_string = new string[n]; + for (ulong i = 0; i < n; i++) + { + arr_string[i] = Console.ReadLine(); + } + + RadixSort(arr_string, n); + } + } +} diff --git a/CourseApp/Module2/Warehouse.cs b/CourseApp/Module2/Warehouse.cs new file mode 100644 index 0000000..acdce6b --- /dev/null +++ b/CourseApp/Module2/Warehouse.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CourseApp.Module2 +{ + public class Warehouse + { + public static void Count_Sort(int[] orders_arr, int[] products_arr, int k) + { + int[] c = new int[k + 1]; + for (int i = 0; i < orders_arr.Length; i++) + { + c[orders_arr[i]]++; + } + + int pos = 0; + int index = 0; + int[] order = new int[k]; + string[] answer = new string[k]; + for (int i = 0; i < c.Length; i++) + { + if (c[i] != 0) + { + order[pos++] = c[i]; + if (products_arr[index] >= order[index]) + { + Console.WriteLine("no"); + } + else + { + Console.WriteLine("yes"); + } + + index++; + } + } + } + public static void Input_Values() + { + int products_len = int.Parse(Console.ReadLine()); + string products_string = Console.ReadLine(); + string[] parseValues = products_string.Split(' '); + int[] products_arr = new int[products_len]; + for (int i = 0; i < products_len; i++) + { + products_arr[i] = int.Parse(parseValues[i]); + } + + int orders_len = int.Parse(Console.ReadLine()); + string orders_string = Console.ReadLine(); + parseValues = orders_string.Split(' '); + int[] orders_arr = new int[orders_len]; + for (int i = 0; i < orders_len; i++) + { + orders_arr[i] = int.Parse(parseValues[i]); + } + + Count_Sort(orders_arr, products_arr, products_len); + } + } +} diff --git a/CourseApp/Module3/CycleSDVG.cs b/CourseApp/Module3/CycleSDVG.cs new file mode 100644 index 0000000..87522b7 --- /dev/null +++ b/CourseApp/Module3/CycleSDVG.cs @@ -0,0 +1,74 @@ +using System; +using System.Linq; + +namespace CourseApp.Module3 +{ + public class CyclicShift + { + public static int Rabin_Karp(string v, string n) + { + if (v == n) + { + return 0; + } + + n = string.Concat(Enumerable.Repeat(n, 2)); + + long w = 13; + long b = 1; + long t = 100000000; + + long first_hash = 0; + long second_hash = 0; + long xt = 1; + + foreach (char i in v.Reverse()) + { + first_hash = (first_hash + (i * b)) % t; + b = (b * w) % t; + } + + b = 1; + + for (int i = v.Length - 1; i >= 0; i--) + { + second_hash = (second_hash + (n[i] * b)) % t; + b = (b * w) % t; + } + + for (int i = 0; i < v.Length - 1; i++) + { + xt = (xt * w) % t; + } + + for (int i = 1; i < n.Length - v.Length + 1; i++) + { + if (first_hash == second_hash) + { + return i - 1; + } + + second_hash = w * (second_hash - (n[i - 1] * xt)); + second_hash += n[i + v.Length - 1]; + second_hash = second_hash % t; + + if ((second_hash < 0 && t > 0) || (second_hash > 0 && t < 0)) + { + second_hash += t; + } + } + + return -1; + } + + public static void EnterValues() + { + string r = Console.ReadLine(); + string q = Console.ReadLine(); + + int result = Rabin_Karp(r, q); + + Console.WriteLine(result); + } + } +} \ No newline at end of file diff --git a/CourseApp/Module3/CycleSTR b/CourseApp/Module3/CycleSTR new file mode 100644 index 0000000..a57eb3b --- /dev/null +++ b/CourseApp/Module3/CycleSTR @@ -0,0 +1,45 @@ +using System; + +namespace CourseApp.Module3 +{ + public class CircularStr + { + public static int[] Prefix_function(string b) + { + int[] res = new int[b.Length]; + res[0] = 0; + + for (int i = 0; i < b.Length - 1; i++) + { + int j = res[i]; + + while (j > 0 && b[i + 1] != b[j]) + { + j = res[j - 1]; + } + + if (b[i + 1] == b[j]) + { + res[i + 1] = j + 1; + } + else + { + res[i + 1] = 0; + } + } + + return res; + } + + public static void EnterVal() + { + string b = Console.ReadLine(); + + int[] prefixs = Prefix_function(b); + + int result = b.Length - prefixs[b.Length - 1]; + + Console.WriteLine(result); + } + } +} \ No newline at end of file diff --git a/CourseApp/Module3/PeriodSTR b/CourseApp/Module3/PeriodSTR new file mode 100644 index 0000000..76ef81d --- /dev/null +++ b/CourseApp/Module3/PeriodSTR @@ -0,0 +1,52 @@ +using System; + +namespace CourseApp.Module3 +{ + public class PeriodStr + { + public static int[] PrefixFunc(string k) + { + int[] res = new int[k.Length]; + res[0] = 0; + + for (int i = 0; i < k.Length - 1; i++) + { + int j = res[i]; + + while (j > 0 && k[i + 1] != k[j]) + { + j = res[j - 1]; + } + + if (k[i + 1] == k[j]) + { + res[i + 1] = j + 1; + } + else + { + res[i + 1] = 0; + } + } + + return res; + } + + public static void EnterVal() + { + string k = Console.ReadLine(); + + int[] prefixs = PrefixFunc(k); + + int result = k.Length - prefixs[k.Length - 1]; + + if (k.Length % result == 0) + { + Console.WriteLine(k.Length / result); + } + else + { + Console.WriteLine(1); + } + } + } +} \ No newline at end of file diff --git a/CourseApp/Module3/TaskFInd.cs b/CourseApp/Module3/TaskFInd.cs new file mode 100644 index 0000000..86e22a6 --- /dev/null +++ b/CourseApp/Module3/TaskFInd.cs @@ -0,0 +1,61 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CourseApp.Module3 +{ + public class TaskFInd + { + public static long Get_hash(string w, int b, int q, int t) + { + long res = 0; + for (int i = 0; i < b; i++) + { + res = ((res * t) + w[i]) % q; + } + + return res; + } + + public static void Rabin_karp(string e, string k, int o, int v) + { + long ht = Get_hash(k, k.Length, o, v); + + long hs = Get_hash(e, k.Length, o, v); + + long xt = 1; + + for (int i = 0; i < k.Length; i++) + { + xt = (xt * v) % o; + } + + for (int i = 0; i <= e.Length - k.Length; i++) + { + if (ht == hs) + { + Console.Write("{0} ", i); + } + + if (i + k.Length < e.Length) + { + hs = ((hs * v) - (e[i] * xt) + e[i + k.Length]) % o; + hs = (hs + o) % o; + } + } + } + + public static void EnterValues() + { + string e = Console.ReadLine(); + string k = Console.ReadLine(); + + int o = 67953405; + int v = 26; + + Rabin_karp(e, k, o, v); + } + } +} \ No newline at end of file diff --git a/CourseApp/Module4/Closmall b/CourseApp/Module4/Closmall new file mode 100644 index 0000000..6dd8361 --- /dev/null +++ b/CourseApp/Module4/Closmall @@ -0,0 +1,81 @@ +using System; + +public class NearSmal +{ + public static void GetNearestSmaller() + { + var numElem = int.Parse(Console.ReadLine()); + var s = Console.ReadLine(); + var sVal = s.Split(' '); + var arrElem = new int[numElem]; + var ansArr = new int[numElem]; + for (int i = 0; i < numElem; i++) + { + arrElem[i] = int.Parse(sVal[i]); + } + + int ind = numElem - 1; + while (ind >= 0) + { + while (Stack.Empty() == false && arrElem[Stack.Back()] >= arrElem[ind]) + { + Stack.Pop(); + } + + if (Stack.Empty() == true) + { + ansArr[ind] = -1; + } + else + { + ansArr[ind] = Stack.Back(); + } + + Stack.Push(ind); + + ind--; + } + + for (int i = 0; i < numElem; i++) + { + Console.Write(ansArr[i] + " "); + } + } + + private class Stack + { + private static int[] buff = new int[100000001]; + private static int top = -1; + + public static void Push(int a) + { + top++; + buff[top] = a; + } + + public static void Pop() + { + top--; + } + + public static int Size() + { + return top + 1; + } + + public static bool Empty() + { + return top == -1; + } + + public static void Clear() + { + top = -1; + } + + public static int Back() + { + return buff[top]; + } + } +} \ No newline at end of file diff --git a/CourseApp/Module4/GetPSP b/CourseApp/Module4/GetPSP new file mode 100644 index 0000000..4110870 --- /dev/null +++ b/CourseApp/Module4/GetPSP @@ -0,0 +1,68 @@ +using System; + +namespace CourseApp.Module4 +{ + public class Psp + { + public static void GetPsp() + { + string parenthes = Console.ReadLine(); + int count = 0; + + for (int i = 0; i < parenthes.Length; i++) + { + if (parenthes[i] == '(') + { + Stack.Push(parenthes[i]); + } + else if (Stack.Empty() == false && parenthes[i] == ')') + { + Stack.Pop(); + } + else + { + count += 1; + } + } + + Console.WriteLine(count + Stack.Size()); + } + + private class Stack + { + private static int[] buf = new int[100000001]; + private static int tp = -1; + + public static void Push(int a) + { + tp++; + buf[tp] = a; + } + + public static void Pop() + { + tp--; + } + + public static int Size() + { + return tp + 1; + } + + public static bool Empty() + { + return tp == -1; + } + + public static void Clr() + { + tp = -1; + } + + public static int Bak() + { + return buf[tp]; + } + } + } +} \ No newline at end of file diff --git a/CourseApp/Module4/MinOtr b/CourseApp/Module4/MinOtr new file mode 100644 index 0000000..36693dd --- /dev/null +++ b/CourseApp/Module4/MinOtr @@ -0,0 +1,137 @@ +using System; + +public class MinSeg +{ + public static void GetMinSeg() + { + string sFirst = Console.ReadLine(); + string[] sFirstVal = sFirst.Split(' '); + int[] arrayFirst = new int[2]; + for (int i = 0; i < 2; i++) + { + arrayFirst[i] = int.Parse(sFirstVal[i]); + } + + string sSecond = Console.ReadLine(); + string[] sSecondVal = sSecond.Split(' '); + int[] arraySecond = new int[arrayFirst[0]]; + for (int i = 0; i < arrayFirst[0]; i++) + { + arraySecond[i] = int.Parse(sSecondVal[i]); + } + + for (int i = 0; i < arrayFirst[1]; i++) + { + while (Deque.Empty() == false && arraySecond[i] < arraySecond[Deque.Front()]) + { + Deque.Pop_Front(); + } + + Deque.Push_Front(i); + } + + for (int i = arrayFirst[1]; i < arrayFirst[0]; i++) + { + Console.WriteLine(arraySecond[Deque.Back()]); + + while (Deque.Empty() == false && Deque.Back() <= i - arrayFirst[1]) + { + Deque.Pop_Back(); + } + + while (Deque.Empty() == false && arraySecond[i] < arraySecond[Deque.Front()]) + { + Deque.Pop_Front(); + if (Deque.Size() == 0) + { + Deque.Clear(); + } + } + + Deque.Push_Front(i); + } + + Console.WriteLine(arraySecond[Deque.Back()]); + } + + private class Deque + { + private static int[] buffer = new int[100000001]; + private static int front = 0; + private static int back = 100000001 - 1; + private static int size = 0; + + public static void Push_Back(int t) + { + back++; + if (back == 100000001) + { + back = 0; + } + + buffer[back] = t; + size++; + } + + public static void Push_Front(int t) + { + front--; + if (front < 0) + { + front = 100000001 - 1; + } + + buffer[front] = t; + size++; + } + + public static void Pop_Back() + { + back--; + if (back < 0) + { + back = 100000001 - 1; + } + + size--; + } + + public static void Pop_Front() + { + front++; + if (front == 100000001) + { + front = 0; + } + + size--; + } + + public static void Clear() + { + front = 0; + back = 100000001 - 1; + size = 0; + } + + public static int Front() + { + return buffer[front]; + } + + public static int Back() + { + return buffer[back]; + } + + public static int Size() + { + return size; + } + + public static bool Empty() + { + return size == 0; + } + } +} diff --git a/CourseApp/Module4/sorttt b/CourseApp/Module4/sorttt new file mode 100644 index 0000000..90b4ca2 --- /dev/null +++ b/CourseApp/Module4/sorttt @@ -0,0 +1,94 @@ +using System; + +namespace CourseApp.Module4 +{ + public class SORT + { + public static void GetSorting() + { + var numbWag = int.Parse(Console.ReadLine()); + var s = Console.ReadLine(); + var sVal = s.Split(' '); + var arrWag = new int[numbWag]; + var ansArr = new int[numbWag]; + for (int i = 0; i < numbWag; i++) + { + arrWag[i] = int.Parse(sVal[i]); + } + + int megaKrut = 0; + int iamGrut = 0; + + while (megaKrut != numbWag) + { + if (Stack.Empty() == true || (iamGrut < numbWag && arrWag[iamGrut] < Stack.Back())) + { + Stack.Push(arrWag[iamGrut]); + iamGrut++; + } + else + { + ansArr[megaKrut] += Stack.Back(); + Stack.Pop(); + megaKrut++; + } + } + + bool isAnswer = true; + + for (int i = 0; i < ansArr.Length - 1; i++) + { + if (ansArr[i] > ansArr[i + 1]) + { + isAnswer = false; + } + } + + if (isAnswer == true) + { + Console.WriteLine("YES"); + } + else + { + Console.WriteLine("NO"); + } + } + + private class Stack + { + private static int[] buffer = new int[100000001]; + private static int top = -1; + + public static void Push(int a) + { + top++; + buffer[top] = a; + } + + public static void Pop() + { + top--; + } + + public static int Size() + { + return top + 1; + } + + public static bool Empty() + { + return top == -1; + } + + public static void Clear() + { + top = -1; + } + + public static int Back() + { + return buffer[top]; + } + } + } +} \ No newline at end of file diff --git a/CourseApp/Module5/Baltree b/CourseApp/Module5/Baltree new file mode 100644 index 0000000..d211d38 --- /dev/null +++ b/CourseApp/Module5/Baltree @@ -0,0 +1,90 @@ +using System; +using System.Collections.Generic; + +namespace CourseApp.Module5.Task_1 +{ + public class IsTreeBalanced + { + private Node root; + + public static void IsTreeBalancedMethod() + { + string s = Console.ReadLine(); + + string[] values = s.Split(' '); + + var tree = new IsTreeBalanced(); + + for (int i = 0; i < values.Length - 1; i++) + { + tree.Insert(int.Parse(values[i])); + } + + if (tree.IsBalanced(tree.root)) + { + Console.WriteLine("YES"); + } + else + { + Console.WriteLine("NO"); + } + } + + public void Insert(int data) + { + root = InnerInsert(data, root); + } + + private Node InnerInsert(int data, Node root) + { + if (root == null) + { + return new Node(data); + } + + if (root.Data > data) + { + root.Left = InnerInsert(data, root.Left); + } + else if (root.Data < data) + { + root.Right = InnerInsert(data, root.Right); + } + + return root; + } + + private bool IsBalanced(Node node) + { + int lh; + + int rh; + + if (node == null) + { + return true; + } + + lh = Height(node.Left); + rh = Height(node.Right); + + if (Math.Abs(lh - rh) <= 1 && IsBalanced(node.Left) + && IsBalanced(node.Right)) + { + return true; + } + + return false; + } + + private int Height(Node node) + { + if (node == null) + { + return 0; + } + + return 1 + Math.Max(Height(node.Left), Height(node.Right)); + } + } +} \ No newline at end of file diff --git a/CourseApp/Module5/Branchtree b/CourseApp/Module5/Branchtree new file mode 100644 index 0000000..dc67a4c --- /dev/null +++ b/CourseApp/Module5/Branchtree @@ -0,0 +1,139 @@ +using System; +using System.Collections.Generic; + +namespace CourseApp.Module5.Task_1 +{ + public class BinarTreeBranch + { + private Node root; + private List size; + + public static void BinaryTreeBranchMethod() + { + string s = Console.ReadLine(); + + string[] sValues = s.Split(' '); + + var tree = new BinarTreeBranch(); + + for (int i = 0; i < sValues.Length - 1; i++) + { + tree.Insert(int.Parse(sValues[i])); + } + + tree.FindLastElem(); + } + + public void Insert(int n) + { + root = InnerInsert(n, root); + } + + public List GetValues() + { + size = new List(); + InnerTraversal(root); + return size; + } + + private bool InnerFind(int n, Node root) + { + if (root == null) + { + return false; + } + + if (n == root.Data) + { + return true; + } + else if (n < root.Data) + { + return InnerFind(n, root.Left); + } + else + { + return InnerFind(n, root.Right); + } + } + + public static void BinaryTreeMethod() + { + throw new NotImplementedException(); + } + + private bool Find(int n) + { + return InnerFind(n, root); + } + + private void FindLastElem() + { + LastElem(root); + } + + private void LastElem(Node value) + { + if (value == null) + { + return; + } + + LastElem(value.Left); + + if ((value.Left != null && value.Right == null) || (value.Right != null && value.Left == null)) + { + Console.WriteLine(value.Data); + } + + LastElem(value.Right); + } + + private Node InnerInsert(int n, Node root) + { + if (root == null) + { + return new Node(n); + } + + if (root.Data > n) + { + root.Left = InnerInsert(n, root.Left); + } + else if (root.Data < n) + { + root.Right = InnerInsert(n, root.Right); + } + + return root; + } + + private void InnerTraversal(Node node) + { + if (node == null) + { + return; + } + + InnerTraversal(node.Left); + size.Add(node.Data); + InnerTraversal(node.Right); + } + + internal class Node + { + public Node(int n) + { + Data = n; + Left = null; + Right = null; + } + + public Node Left { get; set; } + + public Node Right { get; set; } + + public int Data { get; set; } + } + } +} \ No newline at end of file diff --git a/CourseApp/Module5/Node b/CourseApp/Module5/Node new file mode 100644 index 0000000..2953dfc --- /dev/null +++ b/CourseApp/Module5/Node @@ -0,0 +1,18 @@ +namespace CourseApp.Module5.Task_1 +{ + public class Node + { + public Node(int data) + { + Data = data; + Left = null; + Right = null; + } + + public Node Left { get; set; } + + public Node Right { get; set; } + + public int Data { get; set; } + } +} \ No newline at end of file diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs index cafa825..30fd85c 100644 --- a/CourseApp/Program.cs +++ b/CourseApp/Program.cs @@ -7,9 +7,20 @@ public class Program { public static void Main(string[] args) { - BubbleSort.BubbleSortMethod(); + Radix_Sort.Start(); + + // Warehouse.Input_Values(); + + // Numb_Diff.Count_Diff_Method(); + + // Inversion_Sort.Start(); + + // Merge_Sort.Try(); + + // Bubble_Sort_Pair.Bubble_Sort_Method(); + + // Bubble_Sort.Bubble_Sort_Method(); - Console.WriteLine("Hello World"); } } -} +} \ No newline at end of file diff --git a/README.md b/README.md index e58af8a..634160d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Tprogramming_42_2020 - +Kirill Karamysh Master branch :) \ No newline at end of file