diff --git a/CourseApp.Tests/CourseApp.Tests.csproj b/CourseApp.Tests/CourseApp.Tests.csproj
index ae46394..d661f43 100644
--- a/CourseApp.Tests/CourseApp.Tests.csproj
+++ b/CourseApp.Tests/CourseApp.Tests.csproj
@@ -2,7 +2,7 @@
netcoreapp2.1
- True
+ False
1573,1591,1701;1702;1705
false
diff --git a/CourseApp.Tests/Module2/BubbleSortTest.cs b/CourseApp.Tests/Module2/BubbleSortTest.cs
index 8a9b192..96d029a 100644
--- a/CourseApp.Tests/Module2/BubbleSortTest.cs
+++ b/CourseApp.Tests/Module2/BubbleSortTest.cs
@@ -8,11 +8,19 @@ namespace CourseApp.Tests.Module2
[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 Inp2 = @"3
--10 7 2";
+ 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 = @"4
+1 2 3 4";
+
+ private const string Out2 = @"0";
public void Dispose()
{
@@ -24,8 +32,9 @@ 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();
@@ -39,7 +48,8 @@ public void Test1(string input, string expected)
// 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);
}
}
}
diff --git a/CourseApp.Tests/Module2/MergeSortTest.cs b/CourseApp.Tests/Module2/MergeSortTest.cs
new file mode 100644
index 0000000..04cd6ca
--- /dev/null
+++ b/CourseApp.Tests/Module2/MergeSortTest.cs
@@ -0,0 +1,86 @@
+using System;
+using System.IO;
+using Xunit;
+using CourseApp.Module2;
+
+namespace CourseApp.Tests.Module2
+{
+ [Collection("Sequential")]
+ public class MergeSortTest : IDisposable
+ {
+ 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 = @"4
+1 2 3 4";
+
+ private const string Out2 = @"0";
+
+ 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(new int[] { 1 }, new int[] { 2 }, new int[] { 1 , 2 })]
+ [InlineData(new int[] { 1 }, new int[] { 2, 3 }, new int[] { 1, 2, 3 })]
+ [InlineData(new int[] { 5, 6 }, new int[] { 2 }, new int[] { 2, 5, 6 })]
+ [InlineData(new int[] { 1, 3}, new int[] { 3, 4 }, new int[] { 1, 3, 3, 4 })]
+ public void TestMerge(int[] a, int[] b, int[] exp)
+ {
+ var res = MergeSort.Merge(a, b);
+ Assert.Equal(exp, res);
+ }
+
+ [Theory]
+ [InlineData(new int[] { 4, 3, 2, 1 }, new int[] { 4, 3 }, new int[] { 2, 1 })]
+ [InlineData(new int[] { 5, 4, 3, 2, 1 }, new int[] { 5, 4 }, new int[] { 3, 2, 1 })]
+ public void TestSplit(int[] array, int[] leftExp, int[] rightExp)
+ {
+ var (left, right) = MergeSort.Split(array);
+ Assert.Equal(leftExp, left);
+ Assert.Equal(rightExp, right);
+ }
+
+ [Theory]
+ [InlineData(new int[] { 4, 3, 2, 1 }, new int[] { 1, 2, 3, 4 })]
+ [InlineData(new int[] { 5, 4, 3, 2, 1 }, new int[] { 1, 2, 3, 4, 5 })]
+ public void TestSorting(int[] array, int[] expResult)
+ {
+ var result = MergeSort.MergeSorting(array);
+ Assert.Equal(expResult, result);
+ }
+
+ /*[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
+ BubbleSort.BubbleSortMethod();
+
+ // 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/PairSortTest.cs b/CourseApp.Tests/Module2/PairSortTest.cs
new file mode 100644
index 0000000..be38d13
--- /dev/null
+++ b/CourseApp.Tests/Module2/PairSortTest.cs
@@ -0,0 +1,59 @@
+using System;
+using System.IO;
+using Xunit;
+using CourseApp.Module2;
+
+namespace CourseApp.Tests.Module2
+{
+ [Collection("Sequential")]
+ public class PairSortTest : 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
+ PairSort.PairSortMethod();
+
+ // 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/Module2/RadixSortTest.cs b/CourseApp.Tests/Module2/RadixSortTest.cs
new file mode 100644
index 0000000..b38934d
--- /dev/null
+++ b/CourseApp.Tests/Module2/RadixSortTest.cs
@@ -0,0 +1,93 @@
+using System;
+using System.IO;
+using Xunit;
+using CourseApp.Module2;
+
+namespace CourseApp.Tests.Module2
+{
+ [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(new int[] { 1 }, new int[] { 2 }, new int[] { 1, 2 })]
+ [InlineData(new int[] { 1 }, new int[] { 2, 3 }, new int[] { 1, 2, 3 })]
+ [InlineData(new int[] { 5, 6 }, new int[] { 2 }, new int[] { 2, 5, 6 })]
+ [InlineData(new int[] { 1, 3 }, new int[] { 3, 4 }, new int[] { 1, 3, 3, 4 })]
+ public void TestMerge(int[] a, int[] b, int[] exp)
+ {
+ var res = MergeSort.Merge(a, b);
+ Assert.Equal(exp, res);
+ }
+ */
+ [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
+ RadixSort.Main();
+
+ // 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/RabinCarpTest.cs b/CourseApp.Tests/Module3/RabinCarpTest.cs
new file mode 100644
index 0000000..4909b8f
--- /dev/null
+++ b/CourseApp.Tests/Module3/RabinCarpTest.cs
@@ -0,0 +1,74 @@
+using System;
+using System.IO;
+using Xunit;
+using CourseApp.Module3;
+
+namespace CourseApp.Tests.Module3
+{
+ using System;
+ using System.Collections.Generic;
+ using System.IO;
+ using Xunit;
+ using CourseApp.Module3;
+
+ [Collection("Sequential")]
+ public class RabinCarpTest : 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("AB", 3, 7, 1)]
+ [InlineData("BBA", 3, 7, 4)]
+ //[InlineData("ABBA", 3, 7, 5)]
+ //[InlineData("aba", 257, 3571, 907)]
+
+ public void TestHash1(string input, int x, int p, int exp)
+ {
+ var res = RabinCarp.CalculateHash(input, x, p);
+ Assert.Equal(exp, res);
+ }
+
+ [Theory]
+ [InlineData("ABB", 'A', 4, 3, 7, 5)]
+ [InlineData("aba", 'b', 907, 257, 3571, 2422)]
+
+ public void TestSlidingHash1(string input, char append, int hash, int x, int p, int exp)
+ {
+ var res = RabinCarp.SlidingHash(input, append, hash, x, p);
+ Assert.Equal(exp, res);
+ }
+
+ [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
+ RabinCarp.RabinCarpMethod();
+
+ // 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/CourseApp.csproj b/CourseApp/CourseApp.csproj
index 9551450..8221aa2 100644
--- a/CourseApp/CourseApp.csproj
+++ b/CourseApp/CourseApp.csproj
@@ -3,7 +3,7 @@
Exe
netcoreapp2.1
- True
+ False
1573,1591,1701;1702;1705;
diff --git a/CourseApp/Module2/BubbleSort.cs b/CourseApp/Module2/BubbleSort.cs
index cc49214..7aed928 100644
--- a/CourseApp/Module2/BubbleSort.cs
+++ b/CourseApp/Module2/BubbleSort.cs
@@ -17,22 +17,32 @@ public static void BubbleSortMethod()
arr[i] = int.Parse(sValues[i]);
}
+ bool swap = false;
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);
+ swap = true;
}
}
}
- string result = string.Join(" ", arr);
- Console.WriteLine(result);
+ if (swap == false)
+ {
+ Console.WriteLine(0);
+ }
+ }
+
+ /*
+ public static void Main(string[] args)
+ {
+ BubbleSortMethod();
}
+ */
}
}
diff --git a/CourseApp/Module2/CountingSort.cs b/CourseApp/Module2/CountingSort.cs
new file mode 100644
index 0000000..86eb63e
--- /dev/null
+++ b/CourseApp/Module2/CountingSort.cs
@@ -0,0 +1,61 @@
+using System;
+
+namespace CourseApp.Module2
+{
+ public class CountingSort
+ {
+ public static void Main()
+ {
+ int n = int.Parse(Console.ReadLine());
+ string s = Console.ReadLine();
+ string[] sValues = s.Split(' ');
+ int[] warehouse = new int[n];
+ for (int i = 0; i < n; i++)
+ {
+ warehouse[i] = int.Parse(sValues[i]);
+ }
+
+ int k = int.Parse(Console.ReadLine());
+ string p = Console.ReadLine();
+ string[] pValues = p.Split(' ');
+ int[] orders = new int[k];
+ for (int i = 0; i < k; i++)
+ {
+ orders[i] = int.Parse(pValues[i]);
+ }
+
+ int[] aSorted = CountingSorting(orders, k, n);
+
+ // Console.WriteLine("{0}", string.Join(" ", aSorted));
+ Counting(aSorted, warehouse, n);
+ }
+
+ public static int[] CountingSorting(int[] arr, int k, int n)
+ {
+ int[] sort = new int[n];
+ for (int i = 0; i < k; i++)
+ {
+ sort[arr[i] - 1]++;
+ }
+
+ return sort;
+ }
+
+ public static int[] Counting(int[] sort, int[] wareh, int n)
+ {
+ for (int i = 0; i < n; i++)
+ {
+ if (sort[i] > wareh[i])
+ {
+ Console.WriteLine("yes");
+ }
+ else
+ {
+ Console.WriteLine("no");
+ }
+ }
+
+ return sort;
+ }
+ }
+}
\ No newline at end of file
diff --git a/CourseApp/Module2/MergeSort.cs b/CourseApp/Module2/MergeSort.cs
new file mode 100644
index 0000000..618f28a
--- /dev/null
+++ b/CourseApp/Module2/MergeSort.cs
@@ -0,0 +1,64 @@
+namespace CourseApp.Module2
+{
+ public class MergeSort
+ {
+ public static int[] Merge(int[] a, int[] b)
+ {
+ int idxA = 0;
+ int idxB = 0;
+ int k = 0;
+ int[] result = new int[a.Length + b.Length];
+ while (k < result.Length)
+ {
+ // || - или && - и
+ if (idxB == b.Length || (idxA < a.Length && a[idxA] < b[idxB]))
+ {
+ result[k] = a[idxA];
+ idxA++;
+ }
+ else
+ {
+ result[k] = b[idxB];
+ idxB++;
+ }
+
+ k++;
+ }
+
+ return result;
+ }
+
+ public static int[] MergeSorting(int[] array)
+ {
+ if (array.Length == 1)
+ {
+ return array;
+ }
+
+ var (left, right) = Split(array);
+ left = MergeSorting(left);
+ right = MergeSorting(right);
+ return Merge(left, right);
+ }
+
+ public static (int[], int[]) Split(int[] array)
+ {
+ var len = array.Length / 2;
+ int[] left = new int[len];
+ for (int i = 0; i < len; i++)
+ {
+ left[i] = array[i];
+ }
+
+ len = (array.Length / 2) + (array.Length % 2);
+ int[] right = new int[len];
+
+ for (int i = 0; i < len; i++)
+ {
+ right[i] = array[i + len - (array.Length % 2)];
+ }
+
+ return (left, right);
+ }
+ }
+}
diff --git a/CourseApp/Module2/PairSort.cs b/CourseApp/Module2/PairSort.cs
new file mode 100644
index 0000000..b127c2d
--- /dev/null
+++ b/CourseApp/Module2/PairSort.cs
@@ -0,0 +1,54 @@
+using System;
+
+namespace CourseApp.Tests.Module2
+{
+ public class PairSort
+ {
+ public static void PairSortMethod()
+ {
+ int n = int.Parse(Console.ReadLine());
+
+ // для массивов больше ранга 1 в скобках нужна [,]
+ int[,] pair = new int[n, 2];
+ for (int i = 0; i < n; i++)
+ {
+ string s = Console.ReadLine();
+ string[] sValues = s.Split(' ');
+ pair[i, 0] = int.Parse(sValues[0]);
+ pair[i, 1] = int.Parse(sValues[1]);
+ }
+
+ for (int i = 0; i < n - 1; i++)
+ {
+ for (int j = 0; j < n - i - 1; j++)
+ {
+ if (pair[j, 1] < pair[j + 1, 1])
+ {
+ (pair[j, 1], pair[j + 1, 1]) = (pair[j + 1, 1], pair[j, 1]);
+ (pair[j, 0], pair[j + 1, 0]) = (pair[j + 1, 0], pair[j, 0]);
+ }
+ else if (pair[j, 1] == pair[j + 1, 1])
+ {
+ if (pair[j, 0] > pair[j + 1, 0])
+ {
+ (pair[j, 1], pair[j + 1, 1]) = (pair[j + 1, 1], pair[j, 1]);
+ (pair[j, 0], pair[j + 1, 0]) = (pair[j + 1, 0], pair[j, 0]);
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < n; i++)
+ {
+ Console.WriteLine("{0} {1}", pair[i, 0], pair[i, 1]);
+ }
+ }
+
+ /*
+ public static void Main(string[] args)
+ {
+ PairSortMethod();
+ }
+ */
+ }
+}
diff --git a/CourseApp/Module2/RadixSort.cs b/CourseApp/Module2/RadixSort.cs
new file mode 100644
index 0000000..9adbe0d
--- /dev/null
+++ b/CourseApp/Module2/RadixSort.cs
@@ -0,0 +1,141 @@
+using System;
+using System.Linq;
+
+namespace CourseApp.Module2
+{
+ public class RadixSort
+ {
+ public static void Main()
+ {
+ int n = int.Parse(Console.ReadLine());
+ long[] array = new long[n];
+ for (long i = 0; i < n; i++)
+ {
+ array[i] = long.Parse(Console.ReadLine());
+ }
+
+ long r = array.Max();
+ int kol = 0;
+ while (r != 0)
+ {
+ r = r / 10;
+ kol++;
+ }
+
+ var s = string.Concat(Enumerable.Repeat("0", kol));
+
+ string fmt = s + ".##";
+ string formatString = "{0:" + fmt + "}";
+
+ Console.WriteLine("Initial array:");
+ long m = 0;
+ for (long i = 0; i < n; i++)
+ {
+ if (m != n - 1)
+ {
+ Console.Write(formatString, array[i]);
+ Console.Write(", ");
+ m++;
+ }
+ else
+ {
+ Console.Write(formatString, array[i]);
+ }
+ }
+
+ Console.WriteLine();
+ for (int i = 0; i < kol; i++)
+ {
+ Console.WriteLine("**********\nPhase {0}", i + 1);
+ long[,] bucket = Phase1(array, n, formatString, i);
+ array = Form(bucket, n);
+ }
+
+ long k = 0;
+ for (long i = 0; i < n; i++)
+ {
+ if (k != n - 1)
+ {
+ Console.Write(formatString, array[i]);
+ Console.Write(", ");
+
+ k++;
+ }
+ else
+ {
+ Console.Write(formatString, array[i]);
+ }
+ }
+ }
+
+ public static long[] Form(long[,] bucket, long n)
+ {
+ long[] arr = new long[n];
+ long k = 0;
+ for (long i = 0; i < 10; i++)
+ {
+ for (long j = 0; j < n; j++)
+ {
+ if (bucket[i, j] != 0)
+ {
+ arr[k] = bucket[i, j];
+ k++;
+ }
+ }
+ }
+
+ return arr;
+ }
+
+ public static long[,] Phase1(long[] arr, long n, string formatString, long per)
+ {
+ long[,] bucket = new long[10, n];
+ long[] arr_c = new long[n];
+ Array.Copy(arr, arr_c, n);
+
+ for (long i = 0; i < per; i++)
+ {
+ for (long j = 0; j < n; j++)
+ {
+ arr[j] = arr[j] / 10;
+ }
+ }
+
+ for (long i = 0; i < n; i++)
+ {
+ bucket[arr[i] % 10, i] = arr_c[i];
+ }
+
+ long k = 0;
+ for (long i = 0; i < 10; i++)
+ {
+ k = 0;
+ Console.Write("Bucket {0}: ", i);
+ for (long j = 0; j < n; j++)
+ {
+ if (bucket[i, j] != 0 && k == 0)
+ {
+ Console.Write(formatString, bucket[i, j]);
+ k++;
+ }
+ else if (bucket[i, j] != 0 && k != 0)
+ {
+ Console.Write(", ");
+ Console.Write(formatString, bucket[i, j]);
+
+ k++;
+ }
+ }
+
+ if (k == 0)
+ {
+ Console.Write("empty");
+ }
+
+ Console.WriteLine();
+ }
+
+ return bucket;
+ }
+ }
+}
\ No newline at end of file
diff --git a/CourseApp/Module3/LinrPeriod.cs b/CourseApp/Module3/LinrPeriod.cs
new file mode 100644
index 0000000..7f04bfe
--- /dev/null
+++ b/CourseApp/Module3/LinrPeriod.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace CourseApp.Module3
+{
+ public class LinrPeriod
+ {
+ public static void LinePeriodSearch()
+ {
+ string s = Console.ReadLine();
+ string simbol = s;
+ for (int i = 0; i < s.Length / 2; i++)
+ {
+ if (s.Substring(0, i + 1) == s.Substring(i + 1, i + 1))
+ {
+ simbol = s.Substring(0, i + 1);
+ break;
+ }
+ }
+
+ int count = s.Length / simbol.Length;
+ Console.WriteLine(count);
+ }
+ }
+}
diff --git a/CourseApp/Module3/Program.cs b/CourseApp/Module3/Program.cs
new file mode 100644
index 0000000..744270b
--- /dev/null
+++ b/CourseApp/Module3/Program.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using CourseApp.Module3;
+
+namespace CourseApp
+{
+ public class Program
+ {
+ public static int CalculateHash(string s, int x, int p)
+ {
+ int hash = 0;
+ for (int i = 0; i < s.Length; i++)
+ {
+ hash += (s[i] - 'A') * (int)Math.Pow(x, s.Length - 1 - i);
+ }
+
+ return hash % p;
+ }
+
+ public static int SlidingHash(string s, char appended, int hash, int x, int p)
+ {
+ var newHash = (ulong)(hash * x) - ((s[0] - 'A') * Math.Pow(x, s.Length));
+ newHash += appended - 'A';
+ newHash %= p;
+ newHash = (newHash + p) % p;
+ return (int)newHash;
+ }
+
+ public static void RabinCarpMethod()
+ {
+ string s = Console.ReadLine();
+ string t = Console.ReadLine();
+ int x = 257;
+ int p = 3571;
+ var hash_t = CalculateHash(t, x, p);
+ var hash_s = CalculateHash(s.Substring(0, t.Length), x, p);
+ var res = new List();
+ for (int i = 0; i <= s.Length - t.Length; i++)
+ {
+ if (hash_t == hash_s)
+ {
+ var found = true;
+ for (int j = 0; j < t.Length; j++)
+ {
+ if (t[i] != s[i + j])
+ {
+ found = false;
+ break;
+ }
+ }
+
+ if (found)
+ {
+ res.Add(i);
+ }
+ }
+
+ if ((i + t.Length) < s.Length)
+ {
+ var currSubstr = s.Substring(i, i + t.Length);
+ hash_s = SlidingHash(currSubstr, s[i + t.Length], hash_s, x, p);
+ }
+ }
+
+ string result = string.Join(" ", res);
+ Console.WriteLine(result);
+ }
+
+ public static void Main(string[] args)
+ {
+ RabinCarpMethod();
+ Console.WriteLine("Hello World");
+ }
+ }
+}
diff --git a/CourseApp/Module3/RabinCarp.cs b/CourseApp/Module3/RabinCarp.cs
new file mode 100644
index 0000000..b415f20
--- /dev/null
+++ b/CourseApp/Module3/RabinCarp.cs
@@ -0,0 +1,68 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace CourseApp.Module3
+{
+ public class RabinCarp
+ {
+ public static int CalculateHash(string s, int x, int p)
+ {
+ ulong hash = 0;
+ for (int i = 0; i < s.Length; i++)
+ {
+ hash += (ulong)(s[i] - 'A') * (ulong)Math.Pow(x, s.Length - 1 - i);
+ }
+
+ return (int)(hash % (ulong)p);
+ }
+
+ public static int SlidingHash(string s, char appended, int hash, int x, int p)
+ {
+ var newHash = (ulong)(hash * x) - ((s[0] - 'A') * Math.Pow(x, s.Length));
+ newHash += appended - 'A';
+ newHash %= p;
+ newHash = (newHash + p) % p;
+ return (int)newHash;
+ }
+
+ public static void RabinCarpMethod()
+ {
+ string s = Console.ReadLine();
+ string t = Console.ReadLine();
+ int x = 257;
+ int p = 3571;
+ var hash_t = CalculateHash(t, x, p);
+ var hash_s = CalculateHash(s.Substring(0, t.Length), x, p);
+ var res = new List();
+ for (int i = 0; i <= s.Length - t.Length; i++)
+ {
+ if (hash_t == hash_s)
+ {
+ var found = true;
+ for (int j = 0; j < t.Length; j++)
+ {
+ if (t[j] != s[i + j])
+ {
+ found = false;
+ break;
+ }
+ }
+
+ if (found)
+ {
+ res.Add(i);
+ }
+ }
+
+ if ((i + t.Length) < s.Length)
+ {
+ hash_s = SlidingHash(s.Substring(i, t.Length), s[i + t.Length], hash_s, x, p);
+ }
+ }
+
+ string result = string.Join(" ", res);
+ Console.WriteLine(result);
+ }
+ }
+}
diff --git a/CourseApp/Program.cs b/CourseApp/Program.cs
deleted file mode 100644
index cafa825..0000000
--- a/CourseApp/Program.cs
+++ /dev/null
@@ -1,15 +0,0 @@
-using System;
-using CourseApp.Module2;
-
-namespace CourseApp
-{
- public class Program
- {
- public static void Main(string[] args)
- {
- BubbleSort.BubbleSortMethod();
-
- Console.WriteLine("Hello World");
- }
- }
-}
diff --git a/README.md b/README.md
index e58af8a..1f723ec 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,3 @@
# Tprogramming_42_2020
-
+Kazaeva Vitalina 1/147
Master branch :)
\ No newline at end of file
diff --git a/testEnvironments.json b/testEnvironments.json
new file mode 100644
index 0000000..d703575
--- /dev/null
+++ b/testEnvironments.json
@@ -0,0 +1,17 @@
+{
+ "version": "1",
+ "environments": [
+ // По ссылке https://aka.ms/remotetesting
+ // дополнительные сведения о настройке удаленных сред.
+ //{
+ // "name": "WSL Ubuntu",
+ // "type": "wsl",
+ // "wslDistribution": "Ubuntu"
+ //},
+ //{
+ // "name": "Docker dotnet/sdk",
+ // "type": "docker",
+ // "dockerImage": "mcr.microsoft.com/dotnet/sdk"
+ //}
+ ]
+}
\ No newline at end of file