kwest87

Untitled

Apr 11th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.72 KB | None | 0 0
  1. [StrtCode]
  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.                         DeleteElement(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 DeleteElement(ref string[] fullName, ref string[] position)
  80.         {
  81.             int number = Convert.ToInt32(Console.ReadLine());
  82.            
  83.             if (number <= fullName.Length)
  84.             {
  85.                 string[] tempFullname = new string[fullName.Length - 1];
  86.  
  87.                 for (int i = number - 1; i < fullName.Length - 1; i++)
  88.                 {
  89.                     fullName[i] = fullName[i + 1];
  90.                 }
  91.  
  92.                 for (int i = 0; i < fullName.Length - 1; i++)
  93.                 {
  94.                     tempFullname[i] = fullName[i];
  95.                 }
  96.  
  97.                 fullName = tempFullname;;
  98.             }
  99.  
  100.             else
  101.             {
  102.                 Console.WriteLine("Такого в списке нету.");
  103.             }
  104.  
  105.             if (number <= position.Length)
  106.             {
  107.                 string[] tempPosition = new string[position.Length - 1];
  108.  
  109.                 for (int i = number - 1; i < position.Length - 1; i++)
  110.                 {
  111.                     position[i] = position[i + 1];
  112.                 }
  113.  
  114.                 for (int i = 0; i < position.Length - 1; i++)
  115.                 {
  116.                     tempPosition[i] = position[i];
  117.                 }
  118.  
  119.                 position = tempPosition; ;
  120.             }
  121.         }
  122.  
  123.         static void SearchSurname(string[] fullNames, string[] positions)
  124.         {
  125.             Console.WriteLine("Введите фамилию :");
  126.             string surname = Console.ReadLine();
  127.  
  128.             for (int i = 0; i < fullNames.Length; i++)
  129.             {
  130.                 string[] words = fullNames[i].Split(' ');
  131.  
  132.                 if (words[0] == surname)
  133.                 {
  134.                     Console.WriteLine(fullNames[i] + " - " + positions[i]);
  135.                 }
  136.  
  137.                 else
  138.                 {
  139.                     Console.WriteLine("Такого в списке нету.");
  140.                 }
  141.             }
  142.         }
  143.     }
  144. }
  145. [EndCode]
Advertisement
Add Comment
Please, Sign In to add comment