Advertisement
MrVeiran

arsenal

Mar 14th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp55
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] ar =
  14.  
  15.                 {1,2,3,4,5}
  16.             ;
  17.             int[] br =
  18.  
  19.                 {6,7,8,9,10}
  20.             ;
  21.             int end = 0;
  22.             while (end < 2)
  23.             {
  24.                 Console.Clear();
  25.  
  26.                 writeAr(ar);
  27.                 Console.WriteLine();
  28.                 writeAr(br);
  29.                 Console.WriteLine();
  30.                 Console.WriteLine("Выберите работу с каким массивом(1 или 2)");
  31.                 string quest = Console.ReadLine();
  32.                 if (quest!="1"&&quest!="2")
  33.                 {
  34.                     continue;
  35.                 }
  36.                 Console.WriteLine("Выбран массив: "+quest);
  37.                 Console.WriteLine("вам доступны 3 команды");
  38.                 Console.WriteLine("1 активируется кнопкой DEL(Удаляет элемент)");
  39.                 Console.WriteLine("2 команда кнопкой A(Добавляет элемент)");
  40.                 Console.WriteLine("3 команда активируется кнопкой T( транспортирует массив в другой)");
  41.                 Console.WriteLine("Escape чтобы выйти из программы");
  42.                
  43.                 ConsoleKeyInfo charKey = Console.ReadKey();
  44.                 switch (charKey.Key)
  45.                 {
  46.                     case ConsoleKey.Delete:
  47.                         if (quest =="1")
  48.                         {
  49.                             delete(ref ar);
  50.                         }
  51.                         if (quest == "2")
  52.                         {
  53.                             delete(ref br);
  54.                         }
  55.                         else
  56.                         {
  57.                             Console.WriteLine("нет такого массива");
  58.                         }
  59.                         break;
  60.                     case ConsoleKey.A:
  61.                         if (quest == "1")
  62.                         {
  63.                             add(ref ar);
  64.                         }
  65.                         if (quest == "2")
  66.                         {
  67.                             add(ref br);
  68.                         }
  69.                         break;
  70.                     case ConsoleKey.T:
  71.                        
  72.                             perenos(ref ar,ref br,quest);
  73.                        
  74.                            
  75.                        
  76.                         break;
  77.                     case ConsoleKey.Escape:
  78.                         end = 5;
  79.                         break;
  80.                 }
  81.             }
  82.         }
  83.  
  84.         static void delete(ref int[] mas)
  85.         {
  86.             int[] temp = new int[mas.Length - 1];
  87.             Console.Clear();
  88.             Console.WriteLine("В этой функции вы можете удалить определенный элемент");
  89.             Console.WriteLine("Напишите номер(нумерация с ЕДИНИЦЫ) элемента");
  90.             int q = Convert.ToInt32(Console.ReadLine());
  91.             q--;
  92.  
  93.             for (int i = q; i < mas.Length - 1; i++)
  94.             {
  95.  
  96.                 mas[i] = mas[i + 1];
  97.  
  98.  
  99.             }
  100.             for (int i = 0; i < temp.Length; i++)
  101.             {
  102.  
  103.                 temp[i] = mas[i];
  104.  
  105.  
  106.             }
  107.             mas = temp;
  108.  
  109.  
  110.         }
  111.  
  112.  
  113.  
  114.  
  115.  
  116.         static void add(ref int[] mas)
  117.         {
  118.             int[] temp = new int[mas.Length + 1];
  119.             Console.Clear();
  120.             Console.WriteLine("В этой функции вы можете добавить определенный элемент");
  121.             Console.WriteLine("Напишите элемент для добавления. Он будет добавлен в конец массива");
  122.             int q = Convert.ToInt32(Console.ReadLine());
  123.  
  124.  
  125.             for (int i = 0; i < mas.Length; i++)
  126.             {
  127.  
  128.                 temp[i] = mas[i];
  129.  
  130.  
  131.             }
  132.  
  133.  
  134.             temp[temp.Length - 1] = q;
  135.  
  136.  
  137.  
  138.             mas = temp;
  139.  
  140.  
  141.         }
  142.         static void perenos(ref int[] masA, ref int[] masB, string quest)
  143.         {
  144.             string quest2 = "";
  145.             if (quest=="2")
  146.             {
  147.                 quest2 = "1";
  148.             }
  149.             if (quest == "1")
  150.             {
  151.                quest2 = "2";
  152.             }
  153.             Console.Clear();
  154.             Console.WriteLine("Выбран "+ quest+" массив. он будет внедрен в "+ quest2 + " массив");
  155.             if (quest == "1")
  156.             {
  157.               if (masA.Length==masB.Length)
  158.                 {
  159.                     masB = masA;
  160.                 }
  161.               if (masA.Length > masB.Length)
  162.                 {
  163.                     for (int i=0;i<masB.Length;i++)
  164.                     {
  165.                         masB[i] = masA[i];
  166.                     }
  167.                 }
  168.                 if (masA.Length < masB.Length)
  169.                 {
  170.                     for (int i = 0; i < masA.Length; i++)
  171.                     {
  172.                         masB[i] = masA[i];
  173.                     }
  174.                 }
  175.             }
  176.             if (quest == "2")
  177.             {
  178.                 if (masA.Length == masB.Length)
  179.                 {
  180.                     masA = masB;
  181.                 }
  182.                 if (masA.Length > masB.Length)
  183.                 {
  184.                     for (int i = 0; i < masB.Length; i++)
  185.                     {
  186.                         masA[i] = masB[i];
  187.                     }
  188.                 }
  189.                 if (masA.Length < masB.Length)
  190.                 {
  191.                     for (int i = 0; i < masA.Length; i++)
  192.                     {
  193.                         masA[i] = masB[i];
  194.                     }
  195.                 }
  196.             }
  197.  
  198.         }
  199.         static void writeAr(int[] mas)
  200.         {
  201.  
  202.             for (int i = 0; i < mas.Length; i++)
  203.             {
  204.  
  205.                 Console.Write(mas[i]);
  206.                 if (mas[i] < 10)
  207.                 {
  208.                     Console.Write(' ');
  209.                 }
  210.                 Console.Write('|');
  211.             }
  212.  
  213.         }
  214.     }
  215. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement