12Vitaly

19

Sep 6th, 2020 (edited)
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.30 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 egor
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool isOpen = true;
  14.             string[] fullName = { "Обанин Виталий Андреевичь", "Киревичев Егор Николаевичь", "Гордиевских Виктория Андреевна" };
  15.             string[] position = { "Програмист", "Повар", "Маркетолог" };
  16.             string userInput;
  17.  
  18.             while (isOpen == true)
  19.             {
  20.                 Console.WriteLine("1 - Добавить досье.\n2 - Вывести все досье.\n3 - Удолить досье.\n4 - Поиск по фамилии.\n5 - Выход");
  21.                 Console.WriteLine("Введите номер команды.");
  22.                 userInput = Console.ReadLine();
  23.  
  24.                 switch (userInput)
  25.                 {
  26.                     case "1":
  27.                         Console.Write("Введите ФИО: ");
  28.                         userInput = Console.ReadLine();
  29.                         IncreaseArray(ref fullName, userInput);
  30.  
  31.                         Console.Write("Введите должность: ");
  32.                         userInput = Console.ReadLine();
  33.                         ExpandArray(ref position, userInput);
  34.                         break;
  35.                     case "2":
  36.                         WithdrawAllDossiers(fullName, position);
  37.                         break;
  38.                     case "3":
  39.                         for (int i = 0; i < fullName.Length; i++)
  40.                         {
  41.                             Console.Write((i + 1) + "." + fullName[i]);
  42.                             Console.Write(" " + position[i]);
  43.                             if (fullName.Length - 1 != i)
  44.                             {
  45.                                 Console.Write(" - ");
  46.                             }
  47.                         }
  48.  
  49.                         Console.WriteLine("\nВведите номер досье которое хотите удалить. ");
  50.                         int removableDossiers = Convert.ToInt32(Console.ReadLine()) - 1;
  51.                         LessenArray(ref fullName, removableDossiers);
  52.                         LessenArray(ref position, removableDossiers);
  53.                         break;
  54.                     case "4":
  55.                         SearchByLastName(fullName, position);
  56.                         break;
  57.                     case "5":
  58.                         isOpen = false;
  59.                         break;
  60.                 }
  61.             }
  62.         }
  63.  
  64.         static void IncreaseArray(ref string[] receivedArray, string userInput)
  65.         {
  66.             string[] tempReceivedArray = new string[receivedArray.Length + 1];
  67.             for (int i = 0; i < receivedArray.Length; i++)
  68.             {
  69.                 tempReceivedArray[i] = receivedArray[i];
  70.             }
  71.             tempReceivedArray[tempReceivedArray.Length - 1] = userInput;
  72.             receivedArray = tempReceivedArray;
  73.         }
  74.  
  75.  
  76.  
  77.         static void WithdrawAllDossiers(string[] fullName, string[] position)
  78.         {
  79.             for (int i = 0; i < fullName.Length; i++)
  80.             {
  81.                 Console.Write((i + 1) + "." + fullName[i]);
  82.                 Console.Write(" " + position[i]);
  83.                 if (fullName.Length - 1 != i)
  84.                 {
  85.                     Console.Write(" - ");
  86.                 }
  87.             }
  88.             Console.WriteLine();
  89.         }
  90.  
  91.  
  92.         static void LessenArray(ref string[] receivedArray, int removableDossiers)
  93.         {
  94.             string[] tempReceivedArray = new string[receivedArray.Length - 1];
  95.             for (int i = 0; i < removableDossiers; i++)
  96.             {
  97.                 tempReceivedArray[i] = receivedArray[i];
  98.             }
  99.             for (int i = removableDossiers; i < tempReceivedArray.Length; i++)
  100.             {
  101.                 tempReceivedArray[i] = receivedArray[i + 1];
  102.             }
  103.             receivedArray = tempReceivedArray;
  104.         }
  105.  
  106.         static void SearchByLastName(string[] fullName, string[] position)
  107.         {
  108.             bool isOpen = true;
  109.             string userUnput = Console.ReadLine(); ;
  110.             string surname = "";
  111.             while (isOpen == true)
  112.             {
  113.                 for (int i = 0; i < fullName.Length - 1; i++)
  114.                 {
  115.                     string a = fullName[i];
  116.                     for (int j = 0; j < a.Length - 1; j++)
  117.                     {
  118.                         if (a[j] == ' ')
  119.                         {
  120.                             break;
  121.                         }
  122.                         surname += Convert.ToString(a[j]);
  123.                     }
  124.                     if (userUnput == surname)
  125.                     {
  126.                         Console.WriteLine(fullName[i] + " - " + position[i]);
  127.                         isOpen = false;
  128.                     }
  129.                     else if (i == fullName.Length - 1)
  130.                     {
  131.                         Console.WriteLine("Такой фамилии нет");
  132.                         isOpen = false;
  133.                     }
  134.  
  135.                     surname = "";
  136.                 }
  137.             }
  138.         }
  139.     }
  140. }
Add Comment
Please, Sign In to add comment