Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApp55
- {
- class Program
- {
- static void Main(string[] args)
- {
- int[] ar =
- {1,2,3,4,5}
- ;
- int[] br =
- {6,7,8,9,10}
- ;
- int end = 0;
- while (end < 2)
- {
- Console.Clear();
- writeAr(ar);
- Console.WriteLine();
- writeAr(br);
- Console.WriteLine();
- Console.WriteLine("Выберите работу с каким массивом(1 или 2)");
- string quest = Console.ReadLine();
- if (quest!="1"&&quest!="2")
- {
- continue;
- }
- Console.WriteLine("Выбран массив: "+quest);
- Console.WriteLine("вам доступны 3 команды");
- Console.WriteLine("1 активируется кнопкой DEL(Удаляет элемент)");
- Console.WriteLine("2 команда кнопкой A(Добавляет элемент)");
- Console.WriteLine("3 команда активируется кнопкой T( транспортирует массив в другой)");
- Console.WriteLine("Escape чтобы выйти из программы");
- ConsoleKeyInfo charKey = Console.ReadKey();
- switch (charKey.Key)
- {
- case ConsoleKey.Delete:
- if (quest =="1")
- {
- delete(ref ar);
- }
- if (quest == "2")
- {
- delete(ref br);
- }
- else
- {
- Console.WriteLine("нет такого массива");
- }
- break;
- case ConsoleKey.A:
- if (quest == "1")
- {
- add(ref ar);
- }
- if (quest == "2")
- {
- add(ref br);
- }
- break;
- case ConsoleKey.T:
- perenos(ref ar,ref br,quest);
- break;
- case ConsoleKey.Escape:
- end = 5;
- break;
- }
- }
- }
- static void delete(ref int[] mas)
- {
- int[] temp = new int[mas.Length - 1];
- Console.Clear();
- Console.WriteLine("В этой функции вы можете удалить определенный элемент");
- Console.WriteLine("Напишите номер(нумерация с ЕДИНИЦЫ) элемента");
- int q = Convert.ToInt32(Console.ReadLine());
- q--;
- for (int i = q; i < mas.Length - 1; i++)
- {
- mas[i] = mas[i + 1];
- }
- for (int i = 0; i < temp.Length; i++)
- {
- temp[i] = mas[i];
- }
- mas = temp;
- }
- static void add(ref int[] mas)
- {
- int[] temp = new int[mas.Length + 1];
- Console.Clear();
- Console.WriteLine("В этой функции вы можете добавить определенный элемент");
- Console.WriteLine("Напишите элемент для добавления. Он будет добавлен в конец массива");
- int q = Convert.ToInt32(Console.ReadLine());
- for (int i = 0; i < mas.Length; i++)
- {
- temp[i] = mas[i];
- }
- temp[temp.Length - 1] = q;
- mas = temp;
- }
- static void perenos(ref int[] masA, ref int[] masB, string quest)
- {
- string quest2 = "";
- if (quest=="2")
- {
- quest2 = "1";
- }
- if (quest == "1")
- {
- quest2 = "2";
- }
- Console.Clear();
- Console.WriteLine("Выбран "+ quest+" массив. он будет внедрен в "+ quest2 + " массив");
- if (quest == "1")
- {
- if (masA.Length==masB.Length)
- {
- masB = masA;
- }
- if (masA.Length > masB.Length)
- {
- for (int i=0;i<masB.Length;i++)
- {
- masB[i] = masA[i];
- }
- }
- if (masA.Length < masB.Length)
- {
- for (int i = 0; i < masA.Length; i++)
- {
- masB[i] = masA[i];
- }
- }
- }
- if (quest == "2")
- {
- if (masA.Length == masB.Length)
- {
- masA = masB;
- }
- if (masA.Length > masB.Length)
- {
- for (int i = 0; i < masB.Length; i++)
- {
- masA[i] = masB[i];
- }
- }
- if (masA.Length < masB.Length)
- {
- for (int i = 0; i < masA.Length; i++)
- {
- masA[i] = masB[i];
- }
- }
- }
- }
- static void writeAr(int[] mas)
- {
- for (int i = 0; i < mas.Length; i++)
- {
- Console.Write(mas[i]);
- if (mas[i] < 10)
- {
- Console.Write(' ');
- }
- Console.Write('|');
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement