From 49f515858ea0eac50b9bd09d65d3ba9ea74de28b Mon Sep 17 00:00:00 2001 From: PollyFFF Date: Tue, 8 Feb 2022 18:29:53 +0300 Subject: [PATCH 01/47] Update --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e58af8a..dbfa68f 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Tprogramming_42_2020 - +Fedulova Polina Nikolaevna Master branch :) \ No newline at end of file From 8d6d0bd214574416c21ab9b6778e59fd265c6808 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 19:19:05 +0300 Subject: [PATCH 02/47] Create Bubble_Sort --- Module_2/Bubble_Sort | 46 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Module_2/Bubble_Sort diff --git a/Module_2/Bubble_Sort b/Module_2/Bubble_Sort new file mode 100644 index 0000000..797a82d --- /dev/null +++ b/Module_2/Bubble_Sort @@ -0,0 +1,46 @@ +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); + } + } + public static void Main() + { + Bubble_Sort_Method(); + } + } +} + From 89aba825cc90d0af92348a69e86af442222fd81f Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 20:57:12 +0300 Subject: [PATCH 03/47] Create InversionCount --- Module_2/InversionCount | 83 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Module_2/InversionCount diff --git a/Module_2/InversionCount b/Module_2/InversionCount new file mode 100644 index 0000000..3f8aaee --- /dev/null +++ b/Module_2/InversionCount @@ -0,0 +1,83 @@ +using System; + +namespace CourseApp.Module2 +{ + public class InversionCount + { + private static long inversionCount = 0; + + public static void Start() + { + int v = int.Parse(Console.ReadLine()); + if (v > 1) + { + string temp = Console.ReadLine(); + string[] values = temp.Split(' '); + int[] array = new int[v]; + for (int i = 0; i < values.Length; i++) + { + array[i] = int.Parse(values[i]); + } + + int[] result = Sort(array, 0, v); + Console.WriteLine(inversionCount); + } + else + { + Console.WriteLine(0); + } + } + + public static int[] Sort(int[] array, int firstInd, int lastInd) + { + if (lastInd - firstInd == 1) + { + int[] res = new int[1]; + res[0] = array[firstInd]; + return res; + } + + int w = (firstInd + lastInd) / 2; + + int[] left = Sort(array, firstInd, w); + int[] right = Sort(array, w, lastInd); + + return Merge(left, right); + } + + public static int[] Merge(int[] left, int[] right) + { + int i = 0; + int j = 0; + int[] result = new int[left.Length + right.Length]; + + for (int n = 0; n < result.Length; n++) + { + if (i == left.Length) + { + result[n] = right[j]; + j++; + } + else if (j == right.Length) + { + result[n] = left[i]; + i++; + } + else if (left[i] <= right[j]) + { + result[n] = left[i]; + i++; + } + else + { + result[n] = right[j]; + j++; + inversionCount += left.Length - i; + } + } + + return result; + } + } +} + From 15efc3c134ad0ec283b7a04fa68706a7bdf15fbf Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 20:59:52 +0300 Subject: [PATCH 04/47] Create MergeSort --- Module_2/MergeSort | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 Module_2/MergeSort diff --git a/Module_2/MergeSort b/Module_2/MergeSort new file mode 100644 index 0000000..48d50e4 --- /dev/null +++ b/Module_2/MergeSort @@ -0,0 +1,82 @@ +using System; + +namespace CourseApp.Module2 +{ + public class MergeSort + { + public static void Main() + { + MergeSortMethod(); + } + public static void MergeSortMethod() + { + int[] arr = InputParse(); + + int[] sortedArr = ArrSort(ref arr, 0, arr.Length); + + Console.WriteLine("{0}", string.Join(" ", sortedArr)); + } + + private static int[] Merge(ref int[] left, ref int[] right) + { + int i = 0; + int j = 0; + int[] add = new int[left.Length + right.Length]; + for (int k = 0; k < add.Length; k++) + { + if (i == left.Length) + { + add[k] = right[j]; + j++; + } + else if (j == right.Length || left[i] <= right[j]) + { + add[k] = left[i]; + i++; + } + else + { + add[k] = right[j]; + j++; + } + } + + return add; + } + + private static int[] ArrSort(ref int[] arr, int begin, int end) + { + if (end - begin == 1) + { + int[] res = new int[1]; + res[0] = arr[begin]; + return res; + } + + int mid = (begin + end) / 2; + + int[] left = ArrSort(ref arr, begin, mid); + int[] right = ArrSort(ref arr, mid, end); + + int[] sort = Merge(ref left, ref right); + + Console.WriteLine("{0} {1} {2} {3}", begin + 1, end, sort[0], sort[^1]); + + return Merge(ref left, ref right); + } + + private static int[] InputParse() + { + int n = int.Parse(Console.ReadLine()); + int[] arr = new int[n]; + string s = Console.ReadLine(); + string[] sValues = s.Split(' '); + for (int i = 0; i < n; i++) + { + arr[i] = int.Parse(sValues[i]); + } + + return arr; + } + } +} From 89e4bf0c9df021a5dee1278bba9a509d8dfd0940 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:01:02 +0300 Subject: [PATCH 05/47] Create NumberDif --- Module_2/NumberDif | 77 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Module_2/NumberDif diff --git a/Module_2/NumberDif b/Module_2/NumberDif new file mode 100644 index 0000000..c007e2a --- /dev/null +++ b/Module_2/NumberDif @@ -0,0 +1,77 @@ +using System; + +namespace CourseApp.Module2 +{ + public class NumberDif + { + 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 leftInd, int rightInd) + { + int i = leftInd; + int j = rightInd - 1; + int w = array[(leftInd + rightInd - 1) / 2]; + + while (i <= j) + { + while (array[i] < w) + { + i++; + } + + while (array[j] > w) + { + 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 leftInd, int rightInd) + { + if (rightInd - leftInd <= 1) + { + return; + } + + int v = Partition(array, leftInd, rightInd); + + QuickSort(array, leftInd, v); + QuickSort(array, v, rightInd); + } + } +} From a56d2199adeaa855d09813cbcb97171c99efc6c5 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:01:57 +0300 Subject: [PATCH 06/47] Create PairSort --- Module_2/PairSort | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Module_2/PairSort diff --git a/Module_2/PairSort b/Module_2/PairSort new file mode 100644 index 0000000..211a54f --- /dev/null +++ b/Module_2/PairSort @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CourseApp.Module2 +{ + public class PairSort + { + public static void Main() + { + PairSortMethod(); + } + public static void PairSortMethod() + { + int[,] arr = InputParse(); + + int n = arr.Length / 2; + + SortArrFirst(ref arr, ref n); + SortArrSecond(ref arr, ref n); + Show(ref arr, ref n); + } + + private static void SortArrFirst(ref int[,] arr, ref int n) + { + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n - i - 1; j++) + { + if (arr[j + 1, 1] > arr[j, 1]) + { + Swap(ref arr[j, 0], ref arr[j + 1, 0]); + Swap(ref arr[j, 1], ref arr[j + 1, 1]); + } + } + } + } + + private static void SortArrSecond(ref int[,] arr, ref int n) + { + for (int i = 0; i < n; i++) + { + for (int j = 0; j < n - i - 1; j++) + { + if (arr[j + 1, 1] == arr[j, 1] && arr[j + 1, 0] < arr[j, 0]) + { + Swap(ref arr[j, 0], ref arr[j + 1, 0]); + Swap(ref arr[j, 1], ref arr[j + 1, 1]); + } + } + } + } + + private static int[,] InputParse() + { + int n = int.Parse(Console.ReadLine()); + int[,] arr = new int[n, 2]; + for (int i = 0; i < n; i++) + { + string s = Console.ReadLine(); + string[] sValues = s.Split(' '); + for (int j = 0; j < 2; j++) + { + arr[i, j] = int.Parse(sValues[j]); + } + } + + return arr; + } + + private static void Show(ref int[,] arr, ref int n) + { + string result = null; + for (int i = 0; i < n; i++) + { + result = arr[i, 0] + " " + arr[i, 1]; + Console.WriteLine(result); + } + } + + private static void Swap(ref int left, ref int right) + { + int temp = right; + right = left; + left = temp; + } + } +} + From 69035ecb1467d43a2496bcb4d9a19f3c7615e477 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:06:10 +0300 Subject: [PATCH 07/47] Create RadixSort --- Module_2/RadixSort | 80 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 Module_2/RadixSort diff --git a/Module_2/RadixSort b/Module_2/RadixSort new file mode 100644 index 0000000..4bf47c7 --- /dev/null +++ b/Module_2/RadixSort @@ -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 RadixSort + { + public static void RadSort(string[] arr_string) + { + 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 n; + List[] arrayList = new List[10]; + for (n = 0; n < 10; n++) + { + arrayList[n] = 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 (n = 0; n < 10; n++) + { + if (arrayList[n].Count == 0) + { + Console.WriteLine("Bucket " + n + ": empty"); + } + else + { + Console.WriteLine("Bucket " + n + ": {0}", string.Join(", ", arrayList[n])); + } + } + + int l = 0; + + for (n = 0; n < 10; n++) + { + for (int j = 0; j < arrayList[n].Count; j++) + { + arr_string[l] = arrayList[n][j]; + l++; + } + } + + numb_phaze++; + } + + Console.WriteLine("**********"); + Console.WriteLine("Sorted array:"); + Console.Write("{0}", string.Join(", ", arr_string)); + } + + public static void Start() + { + ulong m = ulong.Parse(Console.ReadLine()); + string[] arr_string = new string[m]; + for (ulong i = 0; i < m; i++) + { + arr_string[i] = Console.ReadLine(); + } + + RadSort(arr_string); + } + } +} + From 502e92b16f93f57e7ccf4b906be46b7038b8c417 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:07:23 +0300 Subject: [PATCH 08/47] Create Warehouse --- Module_2/Warehouse | 65 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 Module_2/Warehouse diff --git a/Module_2/Warehouse b/Module_2/Warehouse new file mode 100644 index 0000000..7cb372e --- /dev/null +++ b/Module_2/Warehouse @@ -0,0 +1,65 @@ +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 n) + { + int[] arr = new int[n + 1]; + for (int i = 0; i < orders_arr.Length; i++) + { + arr[orders_arr[i]]++; + } + + int pos = 0; + int index = 0; + int[] ord = new int[n]; + string[] answer = new string[n]; + for (int i = 0; i < arr.Length; i++) + { + if (arr[i] != 0) + { + ord[pos++] = arr[i]; + if (products_arr[index] >= ord[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); + } + } +} From a0146990f64c1c6831b2edfdd56d2f0187d057f3 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:09:10 +0300 Subject: [PATCH 09/47] Create AplusB --- Module_1/AplusB | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 Module_1/AplusB diff --git a/Module_1/AplusB b/Module_1/AplusB new file mode 100644 index 0000000..0407196 --- /dev/null +++ b/Module_1/AplusB @@ -0,0 +1,17 @@ +using System; + +namespace CourseApp.Module1 +{ + public class AplusB + { + public static void Calculate() + { + string s = Console.ReadLine(); + string[] values = s.Split(' '); + int a = int.Parse(values[0]); + int b = int.Parse(values[1]); + Console.WriteLine($"{a + b}"); + } + } +} + From 5e27521c491ec6f60e829ebb6a55ccb0fd3a30d6 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:11:13 +0300 Subject: [PATCH 10/47] =?UTF-8?q?Create=20=E2=84=961?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Module_3/\342\204\2261" | 61 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "Module_3/\342\204\2261" diff --git "a/Module_3/\342\204\2261" "b/Module_3/\342\204\2261" new file mode 100644 index 0000000..da116aa --- /dev/null +++ "b/Module_3/\342\204\2261" @@ -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 Program + { + public static long Get_hash(string a, int b, int c, int d) + { + long res = 0; + for (int i = 0; i < b; i++) + { + res = ((res * d) + a[i]) % c; + } + + return res; + } + + public static void Rabin_karp(string m, string f, int z, int n) + { + long ht = Get_hash(f, f.Length, z, n); + + long hs = Get_hash(m, f.Length, z, n); + + long xt = 1; + + for (int i = 0; i < f.Length; i++) + { + xt = (xt * n) % z; + } + + for (int i = 0; i <= m.Length - f.Length; i++) + { + if (ht == hs) + { + Console.Write("{0} ", i); + } + + if (i + f.Length < m.Length) + { + hs = ((hs * n) - (m[i] * xt) + m[i + f.Length]) % z; + hs = (hs + z) % z; + } + } + } + + public static void Main() + { + string m = Console.ReadLine(); + string f = Console.ReadLine(); + + int z = 67953405; + int n = 26; + + Rabin_karp(m, f, z, n); + } + } +} From 47d58f520239507524e234e20aa3d08d1a329fbe Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:11:57 +0300 Subject: [PATCH 11/47] =?UTF-8?q?Create=20=E2=84=962?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Module_3/\342\204\2262" | 75 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 "Module_3/\342\204\2262" diff --git "a/Module_3/\342\204\2262" "b/Module_3/\342\204\2262" new file mode 100644 index 0000000..0200ea6 --- /dev/null +++ "b/Module_3/\342\204\2262" @@ -0,0 +1,75 @@ +using System; +using System.Linq; + +namespace CourseApp.Module3 +{ + public class Program + { + public static int Rabin_Karp(string s, string t) + { + if (s == t) + { + return 0; + } + + t = string.Concat(Enumerable.Repeat(t, 2)); + + long q = 13; + long m = 1; + long p = 10000000 - 7; + + long first_hash = 0; + long second_hash = 0; + long xt = 1; + + foreach (char i in s.Reverse()) + { + first_hash = (first_hash + (i * m)) % p; + m = (m * q) % p; + } + + m = 1; + + for (int i = s.Length - 1; i >= 0; i--) + { + second_hash = (second_hash + (t[i] * m)) % p; + m = (m * q) % p; + } + + for (int i = 0; i < s.Length - 1; i++) + { + xt = (xt * q) % p; + } + + for (int i = 1; i < t.Length - s.Length + 1; i++) + { + if (first_hash == second_hash) + { + return i - 1; + } + + second_hash = q * (second_hash - (t[i - 1] * xt)); + second_hash += t[i + s.Length - 1]; + second_hash = second_hash % p; + + if ((second_hash < 0 && p > 0) || (second_hash > 0 && p < 0)) + { + second_hash += p; + } + } + + return -1; + } + + public static void Main() + { + string s = Console.ReadLine(); + string t = Console.ReadLine(); + + int result = Rabin_Karp(s, t); + + Console.WriteLine(result); + } + } +} + From 644b5cd2fd0136020e166f5ec8d7976a46139230 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:12:34 +0300 Subject: [PATCH 12/47] =?UTF-8?q?Create=20=E2=84=963?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Module_3/\342\204\2263" | 52 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 "Module_3/\342\204\2263" diff --git "a/Module_3/\342\204\2263" "b/Module_3/\342\204\2263" new file mode 100644 index 0000000..1fb6264 --- /dev/null +++ "b/Module_3/\342\204\2263" @@ -0,0 +1,52 @@ +using System; + +namespace CourseApp.Module3 +{ + public class Program + { + public static int[] PrefixFunc(string w) + { + int[] res = new int[w.Length]; + res[0] = 0; + + for (int i = 0; i < w.Length - 1; i++) + { + int j = res[i]; + + while (j > 0 && w[i + 1] != w[j]) + { + j = res[j - 1]; + } + + if (w[i + 1] == w[j]) + { + res[i + 1] = j + 1; + } + else + { + res[i + 1] = 0; + } + } + + return res; + } + + public static void Main() + { + string w = Console.ReadLine(); + + int[] prefixs = PrefixFunc(w); + + int result = w.Length - prefixs[w.Length - 1]; + + if (w.Length % result == 0) + { + Console.WriteLine(w.Length / result); + } + else + { + Console.WriteLine(1); + } + } + } +} From f2b1621a2582efc42118d36783a9f36739a74c62 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:13:32 +0300 Subject: [PATCH 13/47] =?UTF-8?q?Create=20=E2=84=964?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "Module_3/\342\204\2264" | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 "Module_3/\342\204\2264" diff --git "a/Module_3/\342\204\2264" "b/Module_3/\342\204\2264" new file mode 100644 index 0000000..57eef3a --- /dev/null +++ "b/Module_3/\342\204\2264" @@ -0,0 +1,45 @@ +using System; + +namespace CourseApp.Module3 +{ + public class Program + { + public static int[] Prefix_function(string s) + { + int[] res = new int[s.Length]; + res[0] = 0; + + for (int i = 0; i < s.Length - 1; i++) + { + int j = res[i]; + + while (j > 0 && s[i + 1] != s[j]) + { + j = res[j - 1]; + } + + if (s[i + 1] == s[j]) + { + res[i + 1] = j + 1; + } + else + { + res[i + 1] = 0; + } + } + + return res; + } + + public static void Main() + { + string s = Console.ReadLine(); + + int[] prefixs = Prefix_function(s); + + int result = s.Length - prefixs[s.Length - 1]; + + Console.WriteLine(result); + } + } +} From 09f2299655217d72b4e907991ea15a15342f965f Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:15:51 +0300 Subject: [PATCH 14/47] Create Psp --- Module_4/Psp | 73 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Module_4/Psp diff --git a/Module_4/Psp b/Module_4/Psp new file mode 100644 index 0000000..0708574 --- /dev/null +++ b/Module_4/Psp @@ -0,0 +1,73 @@ +using System; + +namespace CourseApp.Module4 +{ + public class Psp + { + public static void Main() + { + GetPsp(); + } + 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]; + } + } + } +} + From a0729a5d2b5d9a8164114b61dc7c9d7e5518808f Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:16:27 +0300 Subject: [PATCH 15/47] Create SORT --- Module_4/SORT | 99 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 Module_4/SORT diff --git a/Module_4/SORT b/Module_4/SORT new file mode 100644 index 0000000..3b47e06 --- /dev/null +++ b/Module_4/SORT @@ -0,0 +1,99 @@ +using System; + +namespace CourseApp.Module4 +{ + public class SORT + { + public static void Main() + { + GetSorting(); + } + public static void GetSorting() + { + var numbWag = int.Parse(Console.ReadLine()); + var q = Console.ReadLine(); + var sVal = q.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]; + } + } + } +} + From 0a2d839d55c1958b74c589212c01106ee2f639ea Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:18:01 +0300 Subject: [PATCH 16/47] Create NearSmall --- Module_4/NearSmall | 85 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Module_4/NearSmall diff --git a/Module_4/NearSmall b/Module_4/NearSmall new file mode 100644 index 0000000..53e04ce --- /dev/null +++ b/Module_4/NearSmall @@ -0,0 +1,85 @@ +using System; + +public class NearSmall +{ + public static void Main() + { + GetNearestSmaller(); + } + public static void GetNearestSmaller() + { + var numElem = int.Parse(Console.ReadLine()); + var h = Console.ReadLine(); + var sVal = h.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 x) + { + top++; + buff[top] = x; + } + + 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]; + } + } +} From f4aeb0fd0539c00b37531b0513cc18cc2acdf945 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Fri, 3 Jun 2022 21:19:15 +0300 Subject: [PATCH 17/47] Create MinSeg --- Module_4/MinSeg | 142 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 Module_4/MinSeg diff --git a/Module_4/MinSeg b/Module_4/MinSeg new file mode 100644 index 0000000..fe31374 --- /dev/null +++ b/Module_4/MinSeg @@ -0,0 +1,142 @@ +using System; + +public class MinSeg +{ + public static void Main() + { + GetMinSeg(); + } + 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 v) + { + back++; + if (back == 100000001) + { + back = 0; + } + + buffer[back] = v; + size++; + } + + public static void Push_Front(int v) + { + front--; + if (front < 0) + { + front = 100000001 - 1; + } + + buffer[front] = v; + 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; + } + } +} + From 5fdf311223a17aca0fd3d18a83ff14a7206273cd Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 13:47:51 +0300 Subject: [PATCH 18/47] =?UTF-8?q?Update=20and=20rename=20=E2=84=961=20to?= =?UTF-8?q?=20CircularStr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Module_3/CircularStr | 45 +++++++++++++++++++++++++++++ "Module_3/\342\204\2261" | 61 ---------------------------------------- 2 files changed, 45 insertions(+), 61 deletions(-) create mode 100644 Module_3/CircularStr delete mode 100644 "Module_3/\342\204\2261" diff --git a/Module_3/CircularStr b/Module_3/CircularStr new file mode 100644 index 0000000..86c9d25 --- /dev/null +++ b/Module_3/CircularStr @@ -0,0 +1,45 @@ +using System; + +namespace CourseApp.Module3 +{ + public class CircularStr + { + public static int[] Prefix_function(string n) + { + int[] res = new int[n.Length]; + res[0] = 0; + + for (int i = 0; i < n.Length - 1; i++) + { + int j = res[i]; + + while (j > 0 && n[i + 1] != n[j]) + { + j = res[j - 1]; + } + + if (n[i + 1] == n[j]) + { + res[i + 1] = j + 1; + } + else + { + res[i + 1] = 0; + } + } + + return res; + } + + public static void EnterVal() + { + string n = Console.ReadLine(); + + int[] prefixs = Prefix_function(n); + + int result = n.Length - prefixs[n.Length - 1]; + + Console.WriteLine(result); + } + } +} diff --git "a/Module_3/\342\204\2261" "b/Module_3/\342\204\2261" deleted file mode 100644 index da116aa..0000000 --- "a/Module_3/\342\204\2261" +++ /dev/null @@ -1,61 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace CourseApp.Module3 -{ - public class Program - { - public static long Get_hash(string a, int b, int c, int d) - { - long res = 0; - for (int i = 0; i < b; i++) - { - res = ((res * d) + a[i]) % c; - } - - return res; - } - - public static void Rabin_karp(string m, string f, int z, int n) - { - long ht = Get_hash(f, f.Length, z, n); - - long hs = Get_hash(m, f.Length, z, n); - - long xt = 1; - - for (int i = 0; i < f.Length; i++) - { - xt = (xt * n) % z; - } - - for (int i = 0; i <= m.Length - f.Length; i++) - { - if (ht == hs) - { - Console.Write("{0} ", i); - } - - if (i + f.Length < m.Length) - { - hs = ((hs * n) - (m[i] * xt) + m[i + f.Length]) % z; - hs = (hs + z) % z; - } - } - } - - public static void Main() - { - string m = Console.ReadLine(); - string f = Console.ReadLine(); - - int z = 67953405; - int n = 26; - - Rabin_karp(m, f, z, n); - } - } -} From 32f23a704aa834901b1930f2aaa17d35044a33b7 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 13:54:54 +0300 Subject: [PATCH 19/47] =?UTF-8?q?Update=20and=20rename=20=E2=84=962=20to?= =?UTF-8?q?=20CyclicShift?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Module_3/CyclicShift | 75 ++++++++++++++++++++++++++++++++++++++++ "Module_3/\342\204\2262" | 75 ---------------------------------------- 2 files changed, 75 insertions(+), 75 deletions(-) create mode 100644 Module_3/CyclicShift delete mode 100644 "Module_3/\342\204\2262" diff --git a/Module_3/CyclicShift b/Module_3/CyclicShift new file mode 100644 index 0000000..660bb5e --- /dev/null +++ b/Module_3/CyclicShift @@ -0,0 +1,75 @@ +using System; +using System.Linq; + +namespace CourseApp.Module3 +{ + public class CyclicShift + { + public static int Rabin_Karp(string v, string w) + { + if (v == w) + { + return 0; + } + + w = string.Concat(Enumerable.Repeat(w, 2)); + + long a = 13; + long b = 1; + long c = 100000000; + + long first_hash = 0; + long second_hash = 0; + long xt = 1; + + foreach (char i in v.Reverse()) + { + first_hash = (first_hash + (i * b)) % c; + b = (b * a) % c; + } + + b = 1; + + for (int i = v.Length - 1; i >= 0; i--) + { + second_hash = (second_hash + (w[i] * b)) % c; + b = (b * a) % c; + } + + for (int i = 0; i < v.Length - 1; i++) + { + xt = (xt * a) % c; + } + + for (int i = 1; i < w.Length - v.Length + 1; i++) + { + if (first_hash == second_hash) + { + return i - 1; + } + + second_hash = a * (second_hash - (w[i - 1] * xt)); + second_hash += w[i + v.Length - 1]; + second_hash = second_hash % c; + + if ((second_hash < 0 && c > 0) || (second_hash > 0 && c < 0)) + { + second_hash += c; + } + } + + return -1; + } + + public static void EnterValues() + { + string r = Console.ReadLine(); + string q = Console.ReadLine(); + + int result = Rabin_Karp(r, q); + + Console.WriteLine(result); + } + } +} + diff --git "a/Module_3/\342\204\2262" "b/Module_3/\342\204\2262" deleted file mode 100644 index 0200ea6..0000000 --- "a/Module_3/\342\204\2262" +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Linq; - -namespace CourseApp.Module3 -{ - public class Program - { - public static int Rabin_Karp(string s, string t) - { - if (s == t) - { - return 0; - } - - t = string.Concat(Enumerable.Repeat(t, 2)); - - long q = 13; - long m = 1; - long p = 10000000 - 7; - - long first_hash = 0; - long second_hash = 0; - long xt = 1; - - foreach (char i in s.Reverse()) - { - first_hash = (first_hash + (i * m)) % p; - m = (m * q) % p; - } - - m = 1; - - for (int i = s.Length - 1; i >= 0; i--) - { - second_hash = (second_hash + (t[i] * m)) % p; - m = (m * q) % p; - } - - for (int i = 0; i < s.Length - 1; i++) - { - xt = (xt * q) % p; - } - - for (int i = 1; i < t.Length - s.Length + 1; i++) - { - if (first_hash == second_hash) - { - return i - 1; - } - - second_hash = q * (second_hash - (t[i - 1] * xt)); - second_hash += t[i + s.Length - 1]; - second_hash = second_hash % p; - - if ((second_hash < 0 && p > 0) || (second_hash > 0 && p < 0)) - { - second_hash += p; - } - } - - return -1; - } - - public static void Main() - { - string s = Console.ReadLine(); - string t = Console.ReadLine(); - - int result = Rabin_Karp(s, t); - - Console.WriteLine(result); - } - } -} - From 39caecb2527225e086b8914032e3510e99b84a31 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:00:08 +0300 Subject: [PATCH 20/47] =?UTF-8?q?Update=20and=20rename=20=E2=84=963=20to?= =?UTF-8?q?=20FindSubstr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Module_3/FindSubstr | 62 ++++++++++++++++++++++++++++++++++++++++ "Module_3/\342\204\2263" | 52 --------------------------------- 2 files changed, 62 insertions(+), 52 deletions(-) create mode 100644 Module_3/FindSubstr delete mode 100644 "Module_3/\342\204\2263" diff --git a/Module_3/FindSubstr b/Module_3/FindSubstr new file mode 100644 index 0000000..4d9af37 --- /dev/null +++ b/Module_3/FindSubstr @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace CourseApp.Module3 +{ + public class FindSubstr + { + public static long Get_hash(string a, int b, int c, int d) + { + long res = 0; + for (int i = 0; i < b; i++) + { + res = ((res * d) + a[i]) % c; + } + + return res; + } + + public static void Rabin_karp(string m, string f, int z, int n) + { + long ht = Get_hash(f, f.Length, z, n); + + long hs = Get_hash(m, f.Length, z, n); + + long xt = 1; + + for (int i = 0; i < f.Length; i++) + { + xt = (xt * n) % z; + } + + for (int i = 0; i <= m.Length - f.Length; i++) + { + if (ht == hs) + { + Console.Write("{0} ", i); + } + + if (i + f.Length < m.Length) + { + hs = ((hs * n) - (m[i] * xt) + m[i + f.Length]) % z; + hs = (hs + z) % z; + } + } + } + + public static void EnterValues() + { + string m = Console.ReadLine(); + string f = Console.ReadLine(); + + int z = 67953405; + int n = 26; + + Rabin_karp(m, f, z, n); + } + } +} + diff --git "a/Module_3/\342\204\2263" "b/Module_3/\342\204\2263" deleted file mode 100644 index 1fb6264..0000000 --- "a/Module_3/\342\204\2263" +++ /dev/null @@ -1,52 +0,0 @@ -using System; - -namespace CourseApp.Module3 -{ - public class Program - { - public static int[] PrefixFunc(string w) - { - int[] res = new int[w.Length]; - res[0] = 0; - - for (int i = 0; i < w.Length - 1; i++) - { - int j = res[i]; - - while (j > 0 && w[i + 1] != w[j]) - { - j = res[j - 1]; - } - - if (w[i + 1] == w[j]) - { - res[i + 1] = j + 1; - } - else - { - res[i + 1] = 0; - } - } - - return res; - } - - public static void Main() - { - string w = Console.ReadLine(); - - int[] prefixs = PrefixFunc(w); - - int result = w.Length - prefixs[w.Length - 1]; - - if (w.Length % result == 0) - { - Console.WriteLine(w.Length / result); - } - else - { - Console.WriteLine(1); - } - } - } -} From b45969c11f414b8881335c16c3da915b8affac11 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:02:17 +0300 Subject: [PATCH 21/47] =?UTF-8?q?Update=20and=20rename=20=E2=84=964=20to?= =?UTF-8?q?=20PeriodStr?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Module_3/PeriodStr | 52 ++++++++++++++++++++++++++++++++++++++++ "Module_3/\342\204\2264" | 45 ---------------------------------- 2 files changed, 52 insertions(+), 45 deletions(-) create mode 100644 Module_3/PeriodStr delete mode 100644 "Module_3/\342\204\2264" diff --git a/Module_3/PeriodStr b/Module_3/PeriodStr new file mode 100644 index 0000000..65b9750 --- /dev/null +++ b/Module_3/PeriodStr @@ -0,0 +1,52 @@ +using System; + +namespace CourseApp.Module3 +{ + public class PeriodStr + { + public static int[] PrefixFunc(string w) + { + int[] res = new int[w.Length]; + res[0] = 0; + + for (int i = 0; i < w.Length - 1; i++) + { + int j = res[i]; + + while (j > 0 && w[i + 1] != w[j]) + { + j = res[j - 1]; + } + + if (w[i + 1] == w[j]) + { + res[i + 1] = j + 1; + } + else + { + res[i + 1] = 0; + } + } + + return res; + } + + public static void EnterVal() + { + string w = Console.ReadLine(); + + int[] prefixs = PrefixFunc(w); + + int result = w.Length - prefixs[w.Length - 1]; + + if (w.Length % result == 0) + { + Console.WriteLine(w.Length / result); + } + else + { + Console.WriteLine(1); + } + } + } +} diff --git "a/Module_3/\342\204\2264" "b/Module_3/\342\204\2264" deleted file mode 100644 index 57eef3a..0000000 --- "a/Module_3/\342\204\2264" +++ /dev/null @@ -1,45 +0,0 @@ -using System; - -namespace CourseApp.Module3 -{ - public class Program - { - public static int[] Prefix_function(string s) - { - int[] res = new int[s.Length]; - res[0] = 0; - - for (int i = 0; i < s.Length - 1; i++) - { - int j = res[i]; - - while (j > 0 && s[i + 1] != s[j]) - { - j = res[j - 1]; - } - - if (s[i + 1] == s[j]) - { - res[i + 1] = j + 1; - } - else - { - res[i + 1] = 0; - } - } - - return res; - } - - public static void Main() - { - string s = Console.ReadLine(); - - int[] prefixs = Prefix_function(s); - - int result = s.Length - prefixs[s.Length - 1]; - - Console.WriteLine(result); - } - } -} From e7aab56fddd3c6d94d085258e124e0d6cb4cc587 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:07:05 +0300 Subject: [PATCH 22/47] Update MinSeg --- Module_4/MinSeg | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Module_4/MinSeg b/Module_4/MinSeg index fe31374..d3b6978 100644 --- a/Module_4/MinSeg +++ b/Module_4/MinSeg @@ -2,10 +2,6 @@ using System; public class MinSeg { - public static void Main() - { - GetMinSeg(); - } public static void GetMinSeg() { string sFirst = Console.ReadLine(); @@ -139,4 +135,3 @@ public class MinSeg } } } - From 2a662d08b87ff1fa4b23728dbb49aab4804916b6 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:08:39 +0300 Subject: [PATCH 23/47] Update NearSmall --- Module_4/NearSmall | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Module_4/NearSmall b/Module_4/NearSmall index 53e04ce..71e6e19 100644 --- a/Module_4/NearSmall +++ b/Module_4/NearSmall @@ -1,16 +1,12 @@ using System; -public class NearSmall +public class NearSmal { - public static void Main() - { - GetNearestSmaller(); - } public static void GetNearestSmaller() { var numElem = int.Parse(Console.ReadLine()); - var h = Console.ReadLine(); - var sVal = h.Split(' '); + 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++) @@ -83,3 +79,4 @@ public class NearSmall } } } + From 213c25a9c054f56eda9ea4be56a248bd025073d2 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:10:35 +0300 Subject: [PATCH 24/47] Update Psp --- Module_4/Psp | 5 ----- 1 file changed, 5 deletions(-) diff --git a/Module_4/Psp b/Module_4/Psp index 0708574..8b9f4e8 100644 --- a/Module_4/Psp +++ b/Module_4/Psp @@ -4,10 +4,6 @@ namespace CourseApp.Module4 { public class Psp { - public static void Main() - { - GetPsp(); - } public static void GetPsp() { string parenthes = Console.ReadLine(); @@ -70,4 +66,3 @@ namespace CourseApp.Module4 } } } - From 5fd84801d27e919f2d46718c806bea03008cce2d Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:12:05 +0300 Subject: [PATCH 25/47] Update SORT --- Module_4/SORT | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Module_4/SORT b/Module_4/SORT index 3b47e06..aaccf36 100644 --- a/Module_4/SORT +++ b/Module_4/SORT @@ -4,15 +4,11 @@ namespace CourseApp.Module4 { public class SORT { - public static void Main() - { - GetSorting(); - } public static void GetSorting() { var numbWag = int.Parse(Console.ReadLine()); - var q = Console.ReadLine(); - var sVal = q.Split(' '); + 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++) @@ -96,4 +92,3 @@ namespace CourseApp.Module4 } } } - From 9c810e52e489e9cb5cbf4afc011bf698be92c6dc Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:15:09 +0300 Subject: [PATCH 26/47] Create BinarTreeBranch --- Module_5/BinarTreeBranch | 139 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 Module_5/BinarTreeBranch diff --git a/Module_5/BinarTreeBranch b/Module_5/BinarTreeBranch new file mode 100644 index 0000000..63dc18b --- /dev/null +++ b/Module_5/BinarTreeBranch @@ -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 m = Console.ReadLine(); + + string[] sValues = m.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; } + } + } +} From ec6f07d5dfdc5ee11e95bf2cf65715ad02d87922 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:16:54 +0300 Subject: [PATCH 27/47] Create IsTreeBalanced --- Module_5/IsTreeBalanced | 91 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 Module_5/IsTreeBalanced diff --git a/Module_5/IsTreeBalanced b/Module_5/IsTreeBalanced new file mode 100644 index 0000000..f57f284 --- /dev/null +++ b/Module_5/IsTreeBalanced @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; + +namespace CourseApp.Module5.Task_1 +{ + public class IsTreeBalanced + { + private Node root; + + public static void IsTreeBalancedMethod() + { + string f = Console.ReadLine(); + + string[] values = f.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)); + } + } +} + From cc8bff693612e667f50cd28312a79e38303f9273 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:18:05 +0300 Subject: [PATCH 28/47] Create Node --- Module_5/Node | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Module_5/Node diff --git a/Module_5/Node b/Module_5/Node new file mode 100644 index 0000000..f6ada59 --- /dev/null +++ b/Module_5/Node @@ -0,0 +1,19 @@ +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; } + } +} + From a38ac24ab14a176902eff3a265a42a089d98d970 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:55:21 +0300 Subject: [PATCH 29/47] Create AplusBTest --- CourseApp.Tests/Module_1/AplusBTest | 41 +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 CourseApp.Tests/Module_1/AplusBTest diff --git a/CourseApp.Tests/Module_1/AplusBTest b/CourseApp.Tests/Module_1/AplusBTest new file mode 100644 index 0000000..7ed59e8 --- /dev/null +++ b/CourseApp.Tests/Module_1/AplusBTest @@ -0,0 +1,41 @@ +using System; +using System.IO; +using Xunit; +using CourseApp.Module1; + +namespace CourseApp.Tests.Module1 +{ + [Collection("Sequential")] + public class AplusBTest : IDisposable + { + 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("10 12", "22")] + [InlineData("1 1", "2")] + [InlineData("10000 10000", "20000")] + public void Test1(string input, string expected) + { + var stringWriter = new StringWriter(); + Console.SetOut(stringWriter); + + var stringReader = new StringReader(input); + Console.SetIn(stringReader); + + // act + AplusB.Calculate(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + Assert.Equal($"{expected}", output[0]); + var standardOutput = new StreamWriter(Console.OpenStandardOutput()); + } + } +} From d08a11cbeed6d6611a0b1c21516750b5cd93dc90 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:56:19 +0300 Subject: [PATCH 30/47] Create BubbleSortTest --- CourseApp.Tests/Module_2/BubbleSortTest | 50 +++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 CourseApp.Tests/Module_2/BubbleSortTest diff --git a/CourseApp.Tests/Module_2/BubbleSortTest b/CourseApp.Tests/Module_2/BubbleSortTest new file mode 100644 index 0000000..37437cb --- /dev/null +++ b/CourseApp.Tests/Module_2/BubbleSortTest @@ -0,0 +1,50 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class BubbleSortTest : 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"; + + 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 + BubbleSort.BubbleSortMethod(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} From 6e9982ded710bf5c7577f1ad0ab6ca286ba6493d Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:57:20 +0300 Subject: [PATCH 31/47] Create InversionCountTest --- CourseApp.Tests/Module_2/InversionCountTest | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 CourseApp.Tests/Module_2/InversionCountTest diff --git a/CourseApp.Tests/Module_2/InversionCountTest b/CourseApp.Tests/Module_2/InversionCountTest new file mode 100644 index 0000000..a6e8259 --- /dev/null +++ b/CourseApp.Tests/Module_2/InversionCountTest @@ -0,0 +1,53 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class InversionCountTest : 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 + InversionCount.Start(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} + From 7b96ba9b850dee855af939f36668b26a544d736b Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:57:56 +0300 Subject: [PATCH 32/47] Create MergeSortTest --- CourseApp.Tests/Module_2/MergeSortTest | 63 ++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 CourseApp.Tests/Module_2/MergeSortTest diff --git a/CourseApp.Tests/Module_2/MergeSortTest b/CourseApp.Tests/Module_2/MergeSortTest new file mode 100644 index 0000000..cdefa3d --- /dev/null +++ b/CourseApp.Tests/Module_2/MergeSortTest @@ -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 = @"5 +5 4 3 2 1"; + + private const string Out1 = @"1 2 4 5 +4 5 1 2 +3 5 1 3 +1 5 1 5 +1 2 3 4 5"; + + private const string Inp2 = @"1 +1"; + + private const string Out2 = @"1"; + + private const string Inp3 = @"2 +3 1"; + + private const string Out3 = @"1 2 1 3 +1 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)] + [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 + MergeSort.MergeSortMethod(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} From 53a2116a3632ef7e42cd951b5f66f41d5550bf06 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:58:27 +0300 Subject: [PATCH 33/47] Create NumberDifTest --- CourseApp.Tests/Module_2/NumberDifTest | 47 ++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 CourseApp.Tests/Module_2/NumberDifTest diff --git a/CourseApp.Tests/Module_2/NumberDifTest b/CourseApp.Tests/Module_2/NumberDifTest new file mode 100644 index 0000000..0750b47 --- /dev/null +++ b/CourseApp.Tests/Module_2/NumberDifTest @@ -0,0 +1,47 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class NumberDifTest : 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 + NumberDif.Count_Diff_Method(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} + From 5c7cae677c297c0e037ad977a88765c08618aad2 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:59:18 +0300 Subject: [PATCH 34/47] Create PairSortTest --- CourseApp.Tests/Module_2/PairSortTest | 61 +++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 CourseApp.Tests/Module_2/PairSortTest diff --git a/CourseApp.Tests/Module_2/PairSortTest b/CourseApp.Tests/Module_2/PairSortTest new file mode 100644 index 0000000..211cc22 --- /dev/null +++ b/CourseApp.Tests/Module_2/PairSortTest @@ -0,0 +1,61 @@ +namespace CourseApp.Tests.Module2 +{ + using System; + using System.Collections.Generic; + using System.IO; + using CourseApp.Module2; + using Xunit; + + [Collection("Sequential")] + public class PairSortTest : IDisposable + { + private const string Inp1 = @"3 +20 80 +30 90 +25 90"; + + private const string Out1 = @"25 90 +30 90 +20 80"; + + private const string Inp2 = @"3 +101 80 +305 90 +200 14"; + + private const string Out2 = @"305 90 +101 80 +200 14"; + + 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); + } + } +} + From 9656be2ae61e3528428d51a7cdee5404c4e5b6c5 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 14:59:48 +0300 Subject: [PATCH 35/47] Create RadixSortTest --- CourseApp.Tests/Module_2/RadixSortTest | 82 ++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 CourseApp.Tests/Module_2/RadixSortTest diff --git a/CourseApp.Tests/Module_2/RadixSortTest b/CourseApp.Tests/Module_2/RadixSortTest new file mode 100644 index 0000000..cd6b731 --- /dev/null +++ b/CourseApp.Tests/Module_2/RadixSortTest @@ -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 + RadixSort.Start(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} From ec6dc79190ead51bdc9ac0b94ebd7874c6e0ba0d Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:00:31 +0300 Subject: [PATCH 36/47] Create WarehouseTest --- CourseApp.Tests/Module_2/WarehouseTest | 53 ++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 CourseApp.Tests/Module_2/WarehouseTest diff --git a/CourseApp.Tests/Module_2/WarehouseTest b/CourseApp.Tests/Module_2/WarehouseTest new file mode 100644 index 0000000..79cc003 --- /dev/null +++ b/CourseApp.Tests/Module_2/WarehouseTest @@ -0,0 +1,53 @@ +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); + } + } +} + From e24f6fea3a87aa917b7bb879d8de84d5708217f1 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:01:14 +0300 Subject: [PATCH 37/47] Create CircularStrTest --- CourseApp.Tests/Module_3/CircularStrTest | 44 ++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 CourseApp.Tests/Module_3/CircularStrTest diff --git a/CourseApp.Tests/Module_3/CircularStrTest b/CourseApp.Tests/Module_3/CircularStrTest new file mode 100644 index 0000000..b6daba3 --- /dev/null +++ b/CourseApp.Tests/Module_3/CircularStrTest @@ -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); + } + } +} From fd8cb01a49d8af3c1245498feacace830dfd47ef Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:01:42 +0300 Subject: [PATCH 38/47] Create CyclingShiftTest --- CourseApp.Tests/Module_3/CyclingShiftTest | 51 +++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 CourseApp.Tests/Module_3/CyclingShiftTest diff --git a/CourseApp.Tests/Module_3/CyclingShiftTest b/CourseApp.Tests/Module_3/CyclingShiftTest new file mode 100644 index 0000000..37958cc --- /dev/null +++ b/CourseApp.Tests/Module_3/CyclingShiftTest @@ -0,0 +1,51 @@ +namespace CourseApp.Tests.Module3 +{ + using System; + using System.IO; + using CourseApp.Module3; + using Xunit; + + [Collection("Sequential")] + public class CyclingShiftTest : IDisposable + { + private const string Inp1 = @"a + b"; + + private const string Out1 = @"-1"; + + private const string Inp2 = @"zabcd +abcdz"; + + private const string Out2 = @"4"; + + 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 + CyclicShift.EnterValues(); + + // assert + var output = stringWriter.ToString().Split(Environment.NewLine, StringSplitOptions.RemoveEmptyEntries); + var result = string.Join(Environment.NewLine, output); + + Assert.Equal($"{expected}", result); + } + } +} From e2c14cd0b5453e3bb5933622a0435232da370db6 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:02:10 +0300 Subject: [PATCH 39/47] Create FindSubstrTest --- CourseApp.Tests/Module_3/FindSubstrTest | 46 +++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CourseApp.Tests/Module_3/FindSubstrTest diff --git a/CourseApp.Tests/Module_3/FindSubstrTest b/CourseApp.Tests/Module_3/FindSubstrTest new file mode 100644 index 0000000..a2219b2 --- /dev/null +++ b/CourseApp.Tests/Module_3/FindSubstrTest @@ -0,0 +1,46 @@ +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); + } + } +} + From ae0fae71a0e2542d8b98eb02b3dbafaa8fb76d89 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:02:46 +0300 Subject: [PATCH 40/47] Create PeriodStrTest --- CourseApp.Tests/Module_3/PeriodStrTest | 54 ++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 CourseApp.Tests/Module_3/PeriodStrTest diff --git a/CourseApp.Tests/Module_3/PeriodStrTest b/CourseApp.Tests/Module_3/PeriodStrTest new file mode 100644 index 0000000..8501e00 --- /dev/null +++ b/CourseApp.Tests/Module_3/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); + } + } +} From f28471b87a1c2d271cd60731d5e3689ed6f28c03 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:03:39 +0300 Subject: [PATCH 41/47] Create MinSegTest --- CourseApp.Tests/Module_4/MinSegTest | 49 +++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 CourseApp.Tests/Module_4/MinSegTest diff --git a/CourseApp.Tests/Module_4/MinSegTest b/CourseApp.Tests/Module_4/MinSegTest new file mode 100644 index 0000000..c2ac4e3 --- /dev/null +++ b/CourseApp.Tests/Module_4/MinSegTest @@ -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); + } + } +} From ba71e6cd1ecf294e79ca9db1bbc828237726912f Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:04:08 +0300 Subject: [PATCH 42/47] Create NearSmallTest --- CourseApp.Tests/Module_4/NearSmallTest | 46 ++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CourseApp.Tests/Module_4/NearSmallTest diff --git a/CourseApp.Tests/Module_4/NearSmallTest b/CourseApp.Tests/Module_4/NearSmallTest new file mode 100644 index 0000000..9c89618 --- /dev/null +++ b/CourseApp.Tests/Module_4/NearSmallTest @@ -0,0 +1,46 @@ +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); + } + } +} + From 7a9b2546fa220e7dc21cce5fecbbd3800ad48f98 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:04:37 +0300 Subject: [PATCH 43/47] Create PspTest --- CourseApp.Tests/Module_4/PspTest | 50 ++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 CourseApp.Tests/Module_4/PspTest diff --git a/CourseApp.Tests/Module_4/PspTest b/CourseApp.Tests/Module_4/PspTest new file mode 100644 index 0000000..b073622 --- /dev/null +++ b/CourseApp.Tests/Module_4/PspTest @@ -0,0 +1,50 @@ +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); + } + } +} + From 24ce8e89d03a8289ab8410879f76fc2b54d2ab99 Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:05:06 +0300 Subject: [PATCH 44/47] Create SortTest --- CourseApp.Tests/Module_4/SortTest | 59 +++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 CourseApp.Tests/Module_4/SortTest diff --git a/CourseApp.Tests/Module_4/SortTest b/CourseApp.Tests/Module_4/SortTest new file mode 100644 index 0000000..fa0cf5d --- /dev/null +++ b/CourseApp.Tests/Module_4/SortTest @@ -0,0 +1,59 @@ +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); + } + } +} + From 294a84acbdcc47b6c28c764f8ca0c32feee29c8c Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:06:02 +0300 Subject: [PATCH 45/47] Create BinarTreeBranchTest --- CourseApp.Tests/Module_5/BinarTreeBranchTest | 47 ++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 CourseApp.Tests/Module_5/BinarTreeBranchTest diff --git a/CourseApp.Tests/Module_5/BinarTreeBranchTest b/CourseApp.Tests/Module_5/BinarTreeBranchTest new file mode 100644 index 0000000..b090311 --- /dev/null +++ b/CourseApp.Tests/Module_5/BinarTreeBranchTest @@ -0,0 +1,47 @@ +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); + } + } +} + From ae61f1a6a8c83f013e6c06acd71229d979ce876c Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:06:27 +0300 Subject: [PATCH 46/47] Create IsTreeBalancedTest --- CourseApp.Tests/Module_5/IsTreeBalancedTest | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 CourseApp.Tests/Module_5/IsTreeBalancedTest diff --git a/CourseApp.Tests/Module_5/IsTreeBalancedTest b/CourseApp.Tests/Module_5/IsTreeBalancedTest new file mode 100644 index 0000000..946cd27 --- /dev/null +++ b/CourseApp.Tests/Module_5/IsTreeBalancedTest @@ -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 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); + } + } +} + From c24cec6aecd983d311dfd23327364bfda274ae4a Mon Sep 17 00:00:00 2001 From: Fedulova_Polina <96372379+PollyFFF@users.noreply.github.com> Date: Sat, 4 Jun 2022 15:06:55 +0300 Subject: [PATCH 47/47] Delete Node --- Module_5/Node | 19 ------------------- 1 file changed, 19 deletions(-) delete mode 100644 Module_5/Node diff --git a/Module_5/Node b/Module_5/Node deleted file mode 100644 index f6ada59..0000000 --- a/Module_5/Node +++ /dev/null @@ -1,19 +0,0 @@ -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; } - } -} -