kwest87

Untitled

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