Advertisement
Rodunskiy

Untitled

May 11th, 2025
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.79 KB | None | 0 0
  1. namespace CSLight
  2. {
  3.     public class Program
  4.     {
  5.         static void Main(string[] args)
  6.         {
  7.             const string AddDossierCommand = "1";
  8.             const string ShowAllDossierCommand = "2";
  9.             const string SearchLastnameCommand = "3";
  10.             const string DeleteDossierCommand = "4";
  11.             const string ExitProgrammCommand = "5";
  12.  
  13.             Dictionary<string, List<string>> positions = new Dictionary<string, List<string>>();
  14.             bool isRunning = true;
  15.  
  16.             while (isRunning)
  17.             {
  18.                 Console.WriteLine(
  19.                 $"{AddDossierCommand}) Добавить досье\n" +
  20.                 $"{ShowAllDossierCommand}) Вывести все досье\n" +
  21.                 $"{SearchLastnameCommand}) Поиск по фамилии\n" +
  22.                 $"{DeleteDossierCommand}) Удалить досье\n" +
  23.                 $"{ExitProgrammCommand}) Выход из программы\n");
  24.  
  25.                 switch (Console.ReadLine())
  26.                 {
  27.                     case AddDossierCommand:
  28.                         AddDossier(positions);
  29.                         break;
  30.  
  31.                     case ShowAllDossierCommand:
  32.                         ShowAllDossier(positions);
  33.                         break;
  34.  
  35.                     case SearchLastnameCommand:
  36.                         SearchLastname(positions);
  37.                         break;
  38.  
  39.                     case DeleteDossierCommand:
  40.                         DeleteDossier(positions);
  41.                         break;
  42.  
  43.                     case ExitProgrammCommand:
  44.                         isRunning = false;
  45.                         break;
  46.                 }
  47.             }
  48.         }
  49.  
  50.         static void AddDossier(Dictionary<string, List<string>> positions)
  51.         {
  52.             Console.WriteLine("Введите ФИО сотрудника:");
  53.             string fullName = Console.ReadLine();
  54.  
  55.             Console.WriteLine("Введите должность сотрудника:");
  56.             string position = Console.ReadLine();
  57.  
  58.             if (positions.ContainsKey(position))
  59.             {
  60.                 positions[position].Add(fullName);
  61.             }
  62.             else
  63.             {
  64.                 positions[position] = new List<string> { fullName };
  65.             }
  66.  
  67.             Console.WriteLine("Досье добавлено!");
  68.         }
  69.  
  70.         static void ShowAllDossier(Dictionary<string, List<string>> positions)
  71.         {
  72.             if (positions.Count == 0)
  73.             {
  74.                 Console.WriteLine("Досье отсутствуют.");
  75.                 return;
  76.             }
  77.  
  78.             int index = 1;
  79.  
  80.             foreach (var position in positions)
  81.             {
  82.                 Console.WriteLine($"Должность: {position.Key}");
  83.  
  84.                 foreach (var employee in position.Value)
  85.                 {
  86.                     Console.WriteLine($"{index++}) {employee}");
  87.                 }
  88.  
  89.                 Console.WriteLine();
  90.             }
  91.         }
  92.  
  93.         static void SearchLastname(Dictionary<string, List<string>> positions)
  94.         {
  95.             Console.WriteLine("Введите нужную фамилию для поиска:");
  96.             string lastName = Console.ReadLine();
  97.             bool isFound = false;
  98.  
  99.             foreach (var position in positions)
  100.             {
  101.                 foreach (var employee in position.Value)
  102.                 {
  103.                     string[] names = employee.Split(' ');
  104.                     if (names[0].Equals(lastName, StringComparison.OrdinalIgnoreCase))
  105.                     {
  106.                         Console.WriteLine($"{employee} - {position.Key}");
  107.                         isFound = true;
  108.                     }
  109.                 }
  110.             }
  111.  
  112.             if (isFound == false)
  113.             {
  114.                 Console.WriteLine($"Сотрудники с фамилией '{lastName}' не найдены.");
  115.             }
  116.         }
  117.  
  118.         static void DeleteDossier(Dictionary<string, List<string>> positions)
  119.         {
  120.             if (positions.Count == 0)
  121.             {
  122.                 Console.WriteLine("Нет досье для удаления.");
  123.                 return;
  124.             }
  125.  
  126.             Console.WriteLine("Введите должность сотрудника:");
  127.             string position = Console.ReadLine();
  128.  
  129.             if (positions.ContainsKey(position) == false)
  130.             {
  131.                 Console.WriteLine("Должность не найдена.");
  132.                 return;
  133.             }
  134.  
  135.             var employees = positions[position];
  136.             Console.WriteLine("Сотрудники на должности " + position + ":");
  137.  
  138.             for (int i = 0; i < employees.Count; i++)
  139.             {
  140.                 Console.WriteLine($"{i + 1}) {employees[i]}");
  141.             }
  142.  
  143.             Console.WriteLine("Введите номер сотрудника для удаления:");
  144.             int employeeNumber = ReadInt();
  145.  
  146.             if (employeeNumber < 1 || employeeNumber > employees.Count)
  147.             {
  148.                 Console.WriteLine("Неверный номер сотрудника.");
  149.                 return;
  150.             }
  151.  
  152.             employees.RemoveAt(employeeNumber - 1);
  153.             Console.WriteLine("Досье удалено!");
  154.  
  155.             if (employees.Count == 0)
  156.             {
  157.                 positions.Remove(position);
  158.             }
  159.         }
  160.  
  161.         static int ReadInt()
  162.         {
  163.             int number;
  164.  
  165.             while (int.TryParse(Console.ReadLine(), out number) == false)
  166.             {
  167.                 Console.WriteLine("Это не число. Пожалуйста, введите число:");
  168.             }
  169.  
  170.             return number;
  171.         }
  172.     }
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement