kwest87

Untitled

Apr 12th, 2022
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.27 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, ref positions);
  30.                         break;
  31.                     case "2":
  32.                         ShowLists(fullNames, positions, "Список досье :");
  33.                         break;
  34.                     case "3":
  35.                         DeleteElements(ref fullNames,ref positions);
  36.                         break;
  37.                     case "4":
  38.                         SearchSurname(fullNames, positions);
  39.                         break;
  40.                     case "5":
  41.                         exit = true;
  42.                         break;
  43.                 }
  44.             }
  45.         }
  46.  
  47.         static void AddElement(ref string[] fullName, ref string[] position)
  48.         {
  49.             string[] tempFullName = new string[fullName.Length + 1];
  50.             string[] tempPosition = new string[position.Length + 1];
  51.  
  52.             for (int i = 0; i < fullName.Length; i++)
  53.             {
  54.                 tempFullName[i] = fullName[i];
  55.                 tempPosition[i] = position[i];
  56.             }
  57.  
  58.             Console.WriteLine("Добавить ФИО :");
  59.             string newFullName = Convert.ToString(Console.ReadLine());
  60.             tempFullName[tempFullName.Length - 1] = newFullName;
  61.             fullName = tempFullName;
  62.             Console.WriteLine("Добавить должность :");
  63.             string newPosition = Convert.ToString(Console.ReadLine());
  64.             tempPosition[tempPosition.Length - 1] = newPosition;
  65.             position = tempPosition;
  66.         }
  67.  
  68.         static void ShowLists(string[] fullNames, string[] positions, string text)
  69.         {
  70.             Console.WriteLine(text);
  71.             int indent = 1;
  72.  
  73.             for (int i = 0; i < fullNames.Length; i++)
  74.             {
  75.                 Console.WriteLine((i + indent) + ") " + fullNames[i] + " - " + positions[i] + ".");
  76.             }
  77.         }
  78.  
  79.         static void DeleteElements(ref string[] fullName, ref string[] position)
  80.         {
  81.             int number = Convert.ToInt32(Console.ReadLine());
  82.             DeleteElement(ref number, ref fullName);
  83.             DeleteElement(ref number, ref position);
  84.         }
  85.  
  86.         static void SearchSurname(string[] fullNames, string[] positions)
  87.         {
  88.             Console.WriteLine("Введите фамилию :");
  89.             string surname = Console.ReadLine();
  90.  
  91.             for (int i = 0; i < fullNames.Length; i++)
  92.             {
  93.                 string[] words = fullNames[i].Split(' ');
  94.  
  95.                 if (words[0] == surname)
  96.                 {
  97.                     Console.WriteLine(fullNames[i] + " - " + positions[i]);
  98.                 }
  99.  
  100.                 else
  101.                 {
  102.                     Console.WriteLine("Такого в списке нету.");
  103.                 }
  104.             }
  105.         }
  106.  
  107.         static void DeleteElement(ref int number , ref string[] element)
  108.         {
  109.             if (number <= element.Length)
  110.             {
  111.                 string[] tempElement = new string[element.Length - 1];
  112.  
  113.                 for (int i = number - 1; i < element.Length - 1; i++)
  114.                 {
  115.                     element[i] = element[i + 1];
  116.                 }
  117.  
  118.                 for (int i = 0; i < element.Length - 1; i++)
  119.                 {
  120.                     tempElement[i] = element[i];
  121.                 }
  122.  
  123.                 element = tempElement;
  124.             }
  125.         }
  126.     }
  127. }
  128. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment