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 CSLight
- {
- class Menu
- {
- static void Main(string[] args)
- {
- int[] array = new int[0];
- int[] array2 = new int[0];
- bool arrayOperations = true;
- bool addInArray, replaceInArray, delInArray;
- while (arrayOperations == true)
- {
- Console.Clear();
- Console.Write("Первый массив: ");
- for (int i = 0; i < array.Length; i++)
- {
- Console.Write(array[i] + " ");
- }
- Console.Write("\nВторой массив: ");
- for (int i = 0; i < array2.Length; i++)
- {
- Console.Write(array2[i] + " ");
- }
- Console.WriteLine("\n\nДоступные команды: \n\nadd - добавить элемент в массив \ndel - удалить элемент массива \nreplace - перенести один массив в другой \nexit - выход из программы\n");
- Console.Write("\nВаше действие: ");
- switch (Console.ReadLine())
- {
- case "add":
- addInArray = true;
- while (addInArray == true)
- {
- Console.Clear();
- Console.Write("\nВведите номер массива, в который вы хотите добавить число: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- AddInArray(ref array);
- addInArray = false;
- break;
- case 2:
- AddInArray(ref array2);
- addInArray = false;
- break;
- default:
- Console.WriteLine("Такой массив отсутствует!");
- break;
- }
- }
- break;
- case "replace":
- replaceInArray = true;
- while (replaceInArray == true)
- {
- Console.Clear();
- Console.Write("\nВведите номер массива, из которого вы перенести число: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Replace(ref array, ref array2);
- replaceInArray = false;
- break;
- case 2:
- Replace(ref array2, ref array);
- replaceInArray = false;
- break;
- default:
- Console.WriteLine("Такой массив отсутствует!");
- break;
- }
- }
- break;
- case "del":
- delInArray = true;
- while (delInArray == true)
- {
- Console.Clear();
- Console.Write("\nВведите номер массива, из которого вы хотите удалить число: ");
- switch (Convert.ToInt32(Console.ReadLine()))
- {
- case 1:
- Remove(ref array);
- delInArray = false;
- break;
- case 2:
- Remove(ref array2);
- delInArray = false;
- break;
- default:
- Console.WriteLine("Такой массив отсутствует!");
- break;
- }
- }
- break;
- case "exit":
- arrayOperations = false;
- break;
- default:
- ConsoleMessage("\nНеизвестная команда!");
- break;
- }
- }
- }
- static void ConsoleMessage(string message)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine(message);
- Console.ResetColor();
- Console.ReadKey();
- Console.Clear();
- }
- static void Replace(ref int[] array, ref int[] array2)
- {
- Console.Write("\nВведите индекс элемента который хотите перенести: ");
- int input = Convert.ToInt32(Console.ReadLine());
- int index = 0;
- int count = 0;
- for (int i = 0; i < array.Length; ++i)
- {
- if (i == input)
- {
- index = i;
- count = array[i];
- break;
- }
- }
- int[] tempName = new int[array.Length - 1];
- for (int i = 0, j = 0; i < tempName.Length; ++i, ++j)
- {
- if (j == index)
- ++j;
- tempName[i] = array[j];
- }
- array = tempName;
- int[] tempName2 = new int[array2.Length + 1];
- for (int i = 0; i < array2.Length; i++)
- {
- tempName2[i] = array2[i];
- }
- tempName2[tempName2.Length - 1] = count;
- array2 = tempName2;
- }
- static void AddInArray(ref int[] array)
- {
- Console.Write("\nВведите число: ");
- int userInput = Convert.ToInt32(Console.ReadLine());
- int[] tempName = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempName[i] = array[i];
- }
- tempName[tempName.Length - 1] = userInput;
- array = tempName;
- Console.Write("Успешно добавлено!");
- Console.ReadKey();
- }
- static void Remove(ref int[] array)
- {
- Console.Write("\nВведите индекс элемента который хотите удалить: ");
- int input = Convert.ToInt32(Console.ReadLine());
- int index = 0;
- for (int i = 0; i < array.Length; ++i)
- {
- if (i == input)
- {
- index = i;
- break;
- }
- }
- int[] tempName = new int[array.Length - 1];
- for (int i = 0, j = 0; i < tempName.Length; ++i, ++j)
- {
- if (j == index)
- ++j;
- tempName[i] = array[j];
- }
- array = tempName;
- Console.Write("Успешно удалено!");
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment