From 69df87a4c4f48756fcf85828bcd45aa2f5717733 Mon Sep 17 00:00:00 2001 From: mikASho Date: Wed, 9 Feb 2022 13:31:23 +0300 Subject: [PATCH 1/3] =?UTF-8?q?=D0=A4=D0=B0=D0=BC=D0=B8=D0=BB=D0=B8=D1=8F?= =?UTF-8?q?=20=D0=B8=D0=BC=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e58af8a..a44609c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ -# Tprogramming_42_2020 +# Tprogramming_147_2022 -Master branch :) \ No newline at end of file +Shokhin Akim \ No newline at end of file From e32d2ee1e2905024228367d9b8b717971c4a7caa Mon Sep 17 00:00:00 2001 From: mikASho Date: Fri, 11 Feb 2022 14:26:51 +0300 Subject: [PATCH 2/3] =?UTF-8?q?=D0=A4=D0=98=20=D0=BF=D0=BE=D0=BF=D1=8B?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=BD=D1=83=D0=BC=D0=B5=D1=80=202?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a44609c..2d63cee 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,3 @@ # Tprogramming_147_2022 -Shokhin Akim \ No newline at end of file +Shokhin Akim 1/147 \ No newline at end of file From 3e6413620774a16451a945ace8e5f8fe3d5e7f97 Mon Sep 17 00:00:00 2001 From: mikASho Date: Mon, 28 Feb 2022 22:07:32 +0300 Subject: [PATCH 3/3] =?UTF-8?q?=D0=A1=D0=BE=D1=80=D1=82=D0=B8=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CourseApp/Module2/BubbleSort.cs | 50 +++++++++++++++------------ CourseApp/Module2/MergeSort.cs | 33 ++++++++++++++++++ CourseApp/Module2/PairBublSort.cs | 57 +++++++++++++++++++++++++++++++ 3 files changed, 118 insertions(+), 22 deletions(-) create mode 100644 CourseApp/Module2/MergeSort.cs create mode 100644 CourseApp/Module2/PairBublSort.cs diff --git a/CourseApp/Module2/BubbleSort.cs b/CourseApp/Module2/BubbleSort.cs index cc49214..8dd1d40 100644 --- a/CourseApp/Module2/BubbleSort.cs +++ b/CourseApp/Module2/BubbleSort.cs @@ -6,33 +6,39 @@ namespace CourseApp.Module2 { public class BubbleSort { - public static void BubbleSortMethod() + public static void BubbleSortMeth() { - int n = int.Parse(Console.ReadLine()); - string s = Console.ReadLine(); - string[] sValues = s.Split(' '); - int[] arr = new int[n]; - for (int i = 0; i < n; i++) - { - arr[i] = int.Parse(sValues[i]); - } + int arr_size = int.Parse(Console.ReadLine()); + string[] arr_str = Console.ReadLine().Split(' '); + int[] arr = new int[arr_size]; - for (int i = 0; i < arr.Length - 1; i++) - { - for (int j = 0; j < arr.Length - i - 1; j++) + //Строковый массив в целочисенный массив + for(int i = 0; i < arr_size; ++i) { - if (arr[j] > arr[j + 1]) + arr[i] = int.Parse(arr_str[i]); + } + + //Были перестановки или нет + bool flag = false; + //Сортировка + for(int i = 0; i < arr_size; ++i) + { + for(int j = 0; j < arr_size - i - 1; ++j) { - // int temp = arr[j]; - // arr[j] = arr[j + 1]; - // arr[j+1] = temp; - (arr[j], arr[j + 1]) = (arr[j + 1], arr[j]); + if(arr[j] > arr[j+1]) + { + (arr[j], arr[j+1]) = (arr[j+1], arr[j]); + string reslt = string.Join(" ", arr); + Console.WriteLine(reslt); + flag = true; + } } } - } - - string result = string.Join(" ", arr); - Console.WriteLine(result); + + if(flag == false) + { + Console.WriteLine("0"); + } } } -} +} \ No newline at end of file diff --git a/CourseApp/Module2/MergeSort.cs b/CourseApp/Module2/MergeSort.cs new file mode 100644 index 0000000..f4b7458 --- /dev/null +++ b/CourseApp/Module2/MergeSort.cs @@ -0,0 +1,33 @@ + +namespace CourseApp.Module2 +{ + public class MergeSort + { + public static int[] Merge(int[] a, int[] b) + { + int indxA = 0; + int indxB = 0; + int k = 0; + int[] result = new int[a.Length + b.Length]; + int n = a.Length + b.Length; + + while(k < result.Length) + { + if(indxB == b.Length || (indxA < a.Length && a[indxA] < b[indxB])) + { + result[k] = a[indxA]; + indxA++; + } + else + { + result[k] = b[indxA]; + indxB++; + } + k++; + } + + return result; + } + } + +} \ No newline at end of file diff --git a/CourseApp/Module2/PairBublSort.cs b/CourseApp/Module2/PairBublSort.cs new file mode 100644 index 0000000..f2e6e82 --- /dev/null +++ b/CourseApp/Module2/PairBublSort.cs @@ -0,0 +1,57 @@ +using System; + +namespace CourseApp.Module2 +{ + public class PairBublSort + { + public static void PairBubbleSort() + { + + int n = Convert.ToInt32(Console.ReadLine()); + string[] arr_str; + int[,] arr = new int[n, 2]; + + for(int i = 0; i < n; ++i) + { + //Получение строк + string str = Console.ReadLine(); + arr_str = str.Split(' '); + + //Преобразование строк в числа + arr[i, 0] = int.Parse(arr_str[0]); + arr[i, 1] = int.Parse(arr_str[1]); + } + + for(int i = 0; i < n - 1; ++i) + { + for(int j = 0; j < n - 1; ++j) + { + //Сортировка по цене + if(arr[j, 1] < arr[j + 1, 1]) + { + (arr[j + 1, 1], arr[j, 1]) = (arr[j, 1], arr[j + 1, 1]); + (arr[j + 1, 0], arr[j, 0]) = (arr[j, 0], arr[j + 1, 0]); + } + //Сортируем по идентификационному номеру, когда цена одинакова + else if(arr[j, 1] == arr[j + 1, 1]) + { + if(arr[j, 0] > arr[j + 1, 0]) + { + (arr[j + 1, 0], arr[j, 0]) = (arr[j, 0], arr[j + 1, 0]); + } + } + } + } + Console.WriteLine(); + for(int i = 0; i < n; ++i) + { + for(int j = 0; j < 2; ++j) + { + Console.Write(arr[i, j]); + Console.Write(" "); + } + Console.WriteLine(); + } + } + } +}