Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ekaterina zavidina #36

Open
wants to merge 10 commits into
base: Ekaterina_Zavidina
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions CourseApp/Module2/MergeSort.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CourseApp.Module2
{
public class MergeSort
{
public static int[] Merge(int[] a, int[] b)
{
int idxA = 0;
int idxB = 0;
int k = 0;
int[] c = new int[a.Length + b.Length];
while (k < c.Length)
{
if (idxB == b.Length || (idxA < a.Length && a[idxA] < b[idxB]))
{
c[k] = a[idxA];
idxA++;
}
else
{
c[k] = b[idxB];
idxB++;
}
k++;
}
return c;
}
public static int[] Mergee(int[] v, int d, int s)
{
if (s - d == 1)
{
int[] res = new int[1];
res[0] = v[d];
return res;
}

int a = (d + s) / 2;

int[] left = Mergee(v, d, a);
int[] right = Mergee(v, a, s);

int[] sort = Merge(left, right);

Console.WriteLine("{0} {1} {2} {3}", d + 1, s, sort[0], sort[^1]);

return Merge(left, right);
}

public static void Main()
{
int n = int.Parse(Console.ReadLine());
string line = Console.ReadLine();
string[] v = line.Split(' ');
int[] arr = new int[n];
for (int i = 0; i < n; i++)
{
arr[i] = int.Parse(v[i]);
}

int[] sortM = Mergee(arr, 0, n);

Console.WriteLine("{0}", string.Join(" ", sortM));
}
}
}


//int[] Merge(int[] a, int[] b)

79 changes: 79 additions & 0 deletions CourseApp/Module2/NumberOfDifferent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CourseApp.Module2
{
public class NumberOfDifferent
{
private static long count = 1;

public static void Main()
{
int x = int.Parse(Console.ReadLine());
string line = Console.ReadLine();
string[] v = line.Split(' ');
int[] arr = new int[x];
int i;
for (i = 0; i < x; i++)
{
arr[i] = int.Parse(v[i]);
}
Sort(arr, 0, x - 1);

for (i = 1; i < x; i++)
{
if (arr[i - 1] != arr[i])
{
count += 1;
}
}
Console.WriteLine("{0}", count);
}

public static int Conditions(int[] arr, int left, int right)
{
int n = arr[left];
int i = left - 1;
int j = right + 1;

while (true)
{
do
{
i++;
}
while (arr[i] < n);

do
{
j--;
}
while (arr[j] > n);

if (i >= j)
{
return j;
}

int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}

public static void Sort(int[] arr, int left, int right)
{
if (left < right)
{
int num = Number(arr, left, right);

Sort(arr, left, num);
Sort(arr, num + 1, right);
}
}

}
}
72 changes: 72 additions & 0 deletions CourseApp/Module2/NumbeкOfInversions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CourseApp.Module2
{
public class NumbeкOfInversions
{
private static long count = 0;
public static void Main()
{
int x = int.Parse(Console.ReadLine());
string line = Console.ReadLine();
string[] v = line.Split(' ');
int[] arr = new int[x];
for (int i = 0; i < x; i++)
{
arr[i] = int.Parse(v[i]);
}
int[] sortt = Mergee(arr, 0, x);
Console.WriteLine(count);
}
public static int[] Merge(int[] a, int[] b)
{
int idxA = 0;
int idxB = 0;
int c;
int[] k = new int[a.Length + b.Length];
for (c = 0; c < k.Length; c++)
{
if (idxA == a.Length)
{
k[c] = b[idxB];
idxB++;
}
else if (idxB == b.Length || a[idxA] <= b[idxB])
{
k[c] = a[idxA];
idxA++;
}
else
{
k[c] = b[idxB];
idxB++;
count += a.Length - idxA;
}
}

return k;
}

public static int[] Mergee(int[] v, int l, int p)
{
if (p - l == 1)
{
int[] res = new int[1];
res[0] = v[l];
return res;
}

int ser = (l + p) / 2;
int[] left = Mergee(v, l, ser);
int[] right = Mergee(v, ser, p);
int[] sort = Merge(left, right);

return sort;
}
}
}

47 changes: 47 additions & 0 deletions CourseApp/Module2/Sorting.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace CourseApp.Module2
{
public class Sorting
{
public static void Main()
{
int quantity = int.Parse(Console.ReadLine());
int[,] two = new int[quantity, 2];

for (int i = 0; i < quantity; i++)
{
string line = Console.ReadLine();
string[] v = line.Split(' ');
two[i, 0] = int.Parse(v[0]);
two[i, 1] = int.Parse(v[1]);
}
for (int i = 0; i < (two.Length / 2) - 1; i++)
{
for (int j = 0; j < (two.Length / 2) - i - 1; j++)
{
if (two[j, 1] < two[j + 1, 1])
{
(two[j, 1], two[j + 1, 1]) = (two[j + 1, 1], two[j, 1]);
(two[j, 0], two[j + 1, 0]) = (two[j + 1, 0], two[j, 0]);
}
else if (two[j, 1] == two[j + 1, 1])
{
if (two[j, 0] > two[j + 1, 0])
{
(two[j, 0], two[j + 1, 0]) = (two[j + 1, 0], two[j, 0]);
(two[j, 1], two[j + 1, 1]) = (two[j + 1, 1], two[j, 1]);
}
}
}
}

for (int i = 0; i < quantity; i++)
{
Console.WriteLine("{0} {1}", two[i, 0], two[i, 1]);
}
}
}
}
42 changes: 42 additions & 0 deletions CourseApp/Module2/SortingProcess.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CourseApp.Module2
{
public class SortingProcess
{
public static void Main()
{
int numbers = int.Parse(Console.ReadLine());
string line = Console.ReadLine();
string[] v = line.Split(' ');
int[] elements = new int[numbers];
for (int i = 0; i < numbers; i++)
{
elements[i] = int.Parse(v[i]);
}

bool swap = false;
for (int i = 0; i < elements.Length - 1; i++)
{
for (int j = 0; j < elements.Length - i - 1; j++)
{
if (elements[j] > elements[j + 1])
{
(elements[j], elements[j + 1]) = (elements[j + 1], elements[j]);
string conclusion = string.Join(" ", elements);
Console.WriteLine(conclusion);
swap = true;
}
}
}

if (swap == false)
{
Console.WriteLine(0);
}
}
}
}
62 changes: 62 additions & 0 deletions CourseApp/Module2/Warehouse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CourseApp.Module2
{
public class Warehouse
{
public static void Main()
{
int p = int.Parse(Console.ReadLine());
string line = Console.ReadLine();
string[] v = line.Split(' ');
int[] products = new int[p];

for (int i = 0; i < p; i++)
{
products[i] = int.Parse(v[i]);
}
int n = int.Parse(Console.ReadLine());
line = Console.ReadLine();
v = line.Split(' ');
int[] booking = new int[n];
for (int i = 0; i < n; i++)
{
booking[i] = int.Parse(v[i]);
}

Sort(booking, products, p);
}
public static void Sort(int[] booking, int[] products, int k)
{
int[] c = new int[k + 1];
for (int i = 0; i < booking.Length; i++)
{
c[booking[i]]++;
}
int x = 0;
int m = 0;
int[] new_o = new int[k];
string[] arr = new string[k];
for (int i = 0; i < c.Length; i++)
{
if (c[i] != 0)
{
new_o[x++] = c[i];

if (products[m] >= new_o[m])
{
Console.WriteLine("no");
}
else
{
Console.WriteLine("yes");
}
m++;
}
}
}
}
}
Loading