kwest87

Untitled

Apr 11th, 2022
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.11 KB | None | 0 0
  1. [StartCode]
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace ConsoleApp11
  9. {
  10.     internal class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             string[] fullNames = new string[0];
  15.             string[] positions = new string[0];
  16.             string menuOption;
  17.             bool exit = false;
  18.  
  19.             while (exit == false)
  20.             {
  21.                 Console.WriteLine("        МЕНЮ");
  22.                 Console.WriteLine();
  23.                 Console.WriteLine("1 - Добавить досье.\n2 - Список досье.\n3 - Удалить досье.\n4 - Поиск по фамилии.\n5 - Выход.");
  24.                 menuOption = Console.ReadLine();
  25.  
  26.                 switch (menuOption)
  27.                 {
  28.                     case "1":
  29.                         AddElement(ref fullNames, "Добавить ФИО :");
  30.                         AddElement(ref positions, "Добавить должность :");
  31.                         break;
  32.                     case "2":
  33.                         ShowLists(fullNames,positions ,"Список досье :");
  34.                         break;
  35.                     case "3":
  36.                         DeleteElement(ref fullNames, ref positions);
  37.                         break;
  38.                     case "4":
  39.                         SearchSurname(fullNames,positions);
  40.                         break;
  41.                     case "5":
  42.                         exit = true;
  43.                         break;
  44.                 }
  45.             }
  46.         }
  47.  
  48.         static void AddElement(ref string[] array, string text)
  49.         {
  50.             string[] tempArray = new string[array.Length + 1];
  51.  
  52.             for (int i = 0; i < array.Length; i++)
  53.             {
  54.                 tempArray[i] = array[i];
  55.             }
  56.  
  57.             Console.WriteLine(text);
  58.             string newArray = Convert.ToString(Console.ReadLine());
  59.             tempArray[tempArray.Length - 1] = newArray;
  60.             array = tempArray;
  61.         }
  62.  
  63.         static void ShowLists( string[] fullNames, string[] positions, string text)
  64.         {
  65.             Console.WriteLine(text);
  66.             int indent = 1;
  67.  
  68.             for (int i = 0; i < fullNames.Length; i++)
  69.             {
  70.                 Console.WriteLine((i + indent) + ") " + fullNames[i] + " - " + positions[i] + ".");
  71.             }
  72.         }
  73.  
  74.         static void DeleteElement(ref string[] fullName, ref string[] position)
  75.         {
  76.             int number = Convert.ToInt32(Console.ReadLine());
  77.            
  78.             if (number <= fullName.Length)
  79.             {
  80.                 for (int i = number - 1; i < fullName.Length - 1; i++)
  81.                 {
  82.                     fullName[i] = fullName[i + 1];
  83.                     position[i] = position[i + 1];
  84.                 }
  85.  
  86.                 string[] tempFullname = new string[fullName.Length - 1];
  87.                 string[] tempPosotion = new string[position.Length - 1];
  88.  
  89.                 for (int i = 0; i < fullName.Length - 1; i++)
  90.                 {
  91.                     tempFullname[i] = fullName[i];
  92.                     tempPosotion[i] = position[i];
  93.                 }
  94.  
  95.                 fullName = tempFullname;
  96.                 position = tempPosotion;
  97.             }
  98.  
  99.             else
  100.             {
  101.                 Console.WriteLine("Такого в списке нету.");
  102.             }
  103.         }
  104.  
  105.         static void SearchSurname(string[] fullNames, string[] positions)
  106.         {
  107.             Console.WriteLine("Введите фамилию :");
  108.             string surname = Console.ReadLine();
  109.  
  110.             for (int i = 0; i < fullNames.Length; i++)
  111.             {
  112.                 string[] words = fullNames[i].Split(' ');
  113.  
  114.                 if (words[0] == surname)
  115.                 {
  116.                     Console.WriteLine(fullNames[i] + " - " + positions[i]);
  117.                 }
  118.  
  119.                 else
  120.                 {
  121.                     Console.WriteLine("Такого в списке нету.");
  122.                 }
  123.             }
  124.         }
  125.     }
  126. }
  127. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment