Skip to content

Instantly share code, notes, and snippets.

@VladimirYus
Last active January 15, 2026 14:52
Show Gist options
  • Select an option

  • Save VladimirYus/55bc65f59f2054af463d5af94faeee53 to your computer and use it in GitHub Desktop.

Select an option

Save VladimirYus/55bc65f59f2054af463d5af94faeee53 to your computer and use it in GitHub Desktop.
PersonnelRecordsImproved
using System;
using System.Collections.Generic;
namespace PersonnelRecords
{
internal class Program
{
static void Main(string[] args)
{
const string CommandAddDossier = "1";
const string CommandShowDoissers = "2";
const string CommandDeleteDossier = "3";
const string CommandExit = "4";
var personnel = new Dictionary<string, List<string>>();
string inputCommand;
bool isWork = true;
while (isWork)
{
Console.WriteLine($"{CommandAddDossier} - Добавить досье");
Console.WriteLine($"{CommandShowDoissers} - Вывести все досье");
Console.WriteLine($"{CommandDeleteDossier} - Удалить досье");
Console.WriteLine($"{CommandExit} - Выход");
inputCommand = Console.ReadLine();
switch (inputCommand)
{
case CommandAddDossier:
AddEmployee(personnel);
break;
case CommandShowDoissers:
ShowEmployees(personnel);
break;
case CommandDeleteDossier:
DeleteEmployee(personnel);
break;
case CommandExit:
isWork = false;
Console.WriteLine("Программа завершена.");
break;
default:
Console.WriteLine("Неверная команда. Попробуйте снова.");
break;
}
}
}
static void AddEmployee(Dictionary<string, List<string>> personnel)
{
Console.Write("Введите ФИО сотрудника: ");
string fullName = Console.ReadLine();
Console.Write("Введите должность: ");
string jobTitle = Console.ReadLine();
if (personnel.ContainsKey(jobTitle) == false)
{
personnel[jobTitle] = new List<string>();
}
personnel[jobTitle].Add(fullName);
Console.WriteLine($"Сотрудник {fullName} добавлен на должность {jobTitle}.");
}
static void ShowEmployees(Dictionary<string, List<string>> personnel)
{
if (personnel.Count == 0)
{
Console.WriteLine("Данных о сотрудниках нет.");
return;
}
Console.WriteLine("\nСписок сотрудников по должностям:");
foreach (var entry in personnel)
{
Console.WriteLine($"Должность: {entry.Key}");
foreach (string employee in entry.Value)
{
Console.WriteLine($" - {employee}");
}
}
}
static void DeleteEmployee(Dictionary<string, List<string>> personnel)
{
if (personnel.Count == 0)
{
Console.WriteLine("Сотрудников нет.");
return;
}
Console.Write("Введите должность сотрудника для удаления: ");
string jobTitle = Console.ReadLine();
if (personnel.ContainsKey(jobTitle) == false)
{
Console.WriteLine($"Должность '{jobTitle}' не найдена.");
return;
}
var employees = personnel[jobTitle];
if (employees.Count == 0)
{
Console.WriteLine($"На должности '{jobTitle}' нет сотрудников.");
return;
}
Console.WriteLine($"Сотрудники на должности '{jobTitle}':");
for (int i = 0; i < employees.Count; i++)
{
Console.WriteLine($"{i + 1}. {employees[i]}");
}
Console.Write("Введите номер сотрудника для удаления: ");
string input = Console.ReadLine();
int index;
if (int.TryParse(input, out index) == false || index < 1 || index > employees.Count)
{
Console.WriteLine("Неверный номер. Удаление отменено.");
return;
}
string fullName = employees[index - 1];
employees.RemoveAt(index - 1);
Console.WriteLine($"Сотрудник {fullName} удалён с должности {jobTitle}.");
if (employees.Count == 0)
{
personnel.Remove(jobTitle);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment