Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Lesson_4
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[,] names = new string[0, 3];
- string[] stafs = new string[0];
- bool exit = false;
- while (!exit)
- {
- Console.Clear();
- ShowMenu();
- Console.Write("Выберите действие: ");
- ConsoleKeyInfo action = Console.ReadKey();
- Console.WriteLine();
- switch (action.Key)
- {
- case ConsoleKey.D1:
- Add(ref names, ref stafs);
- Console.WriteLine("Нажмите любую клавишу для продолжения...");
- Console.ReadKey();
- break;
- case ConsoleKey.D2:
- Console.WriteLine();
- ShowAll(names, stafs);
- Console.WriteLine();
- Console.WriteLine("Нажмите любую клавишу для продолжения...");
- Console.ReadKey();
- break;
- case ConsoleKey.D3:
- Remove(ref names, ref stafs);
- Console.WriteLine("Нажмите любую клавишу для продолжения...");
- Console.ReadKey();
- break;
- case ConsoleKey.D4:
- Console.Write("Кого вы хотите найти: ");
- string surname = Console.ReadLine();
- Console.WriteLine();
- int[] result = Search(names, stafs, surname);
- Console.WriteLine($"По Вашему запрсу найдено {result.Length} результатов:");
- ShowInfo(names, stafs, result);
- Console.WriteLine("Нажмите любую клавишу для продолжения...");
- Console.ReadKey();
- break;
- case ConsoleKey.D0:
- exit = true;
- break;
- }
- }
- }
- static void ShowMenu()
- {
- Console.WriteLine("1. Добавить досье;\n2. Вывесть все досье;\n3. Удалить досье;\n4. Найти досье;\n0. Выход.");
- }
- static int[] Search(string[,] names, string[] stafs, string surname)
- {
- int[] result = new int[0];
- int count = 0;
- for (int i = 0; i < names.GetLength(0); i++)
- {
- if (names[i, 0] == surname)
- {
- result = Expansion(result);
- result[count++] = i;
- }
- }
- return result;
- }
- static int[] Expansion(int[] array)
- {
- int[] temp = new int[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- temp[i] = array[i];
- }
- return temp;
- }
- static string[] Expansion(string[] array)
- {
- string[] temp = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- temp[i] = array[i];
- }
- return temp;
- }
- static string[,] Expansion(string[,] array)
- {
- string[,] temp = new string[array.GetLength(0) + 1, array.GetLength(1)];
- for (int i = 0; i < array.GetLength(0); i++)
- {
- for (int j = 0; j < array.GetLength(1); j++)
- {
- temp[i, j] = array[i, j];
- }
- }
- return temp;
- }
- static void Add(ref string[,] names, ref string[] stafs)
- {
- Console.Write("Введите имя: ");
- string name = Console.ReadLine();
- Console.Write("Введите фамилию: ");
- string surname = Console.ReadLine();
- Console.Write("Введите отчество: ");
- string patronymic = Console.ReadLine();
- Console.Write("Введите должность: ");
- string staf = Console.ReadLine();
- names = Expansion(names);
- stafs = Expansion(stafs);
- names[names.GetLength(0) - 1, 0] = surname;
- names[names.GetLength(0) - 1, 1] = name;
- names[names.GetLength(0) - 1, 2] = patronymic;
- stafs[stafs.Length - 1] = staf;
- }
- static void Remove(ref string[,] names, ref string[] stafs)
- {
- if (stafs.Length != 0)
- {
- ShowAll(names, stafs);
- Console.Write("Кого Вы хотите удилить: ");
- string surname = Console.ReadLine();
- int[] result = Search(names, stafs, surname);
- if (result.Length != 0)
- {
- string[,] tempNames = new string[names.GetLength(0) - result.Length, names.GetLength(1)];
- string[] tempStafs = new string[stafs.Length - result.Length];
- int offset = 0;
- for (int i = 0; i < tempNames.GetLength(0); i++)
- {
- if (Contains(result,i))
- {
- offset++;
- }
- for (int j = 0; j < tempNames.GetLength(1); j++)
- {
- tempNames[i, j] = names[i+offset, j];
- }
- tempStafs[i] = stafs[i+offset];
- }
- names = tempNames;
- stafs = tempStafs;
- }
- }
- else
- {
- Console.WriteLine("Досье отсутствуют!");
- Console.ReadKey();
- }
- }
- static bool Contains(int[] array, int number)
- {
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == number)
- {
- return true;
- }
- }
- return false;
- }
- static void ShowAll(string[,] names, string[] stafs)
- {
- for (int i = 0; i < stafs.Length; i++)
- {
- char ending = i == stafs.Length - 1 ? '.' : ';';
- Console.WriteLine($"{i + 1}. {names[i, 0]} {names[i, 1]} {names[i, 2]} - {stafs[i]}{ending}");
- }
- }
- static void ShowInfo(string[,] names, string[] stafs, int[] numbers)
- {
- if (names.Length != 0)
- {
- for (int i = 0; i < numbers.Length; i++)
- {
- char ending = i == names.Length - 1 ? '.' : ';';
- Console.WriteLine($"{i + 1}. {names[numbers[i], 0]} {names[numbers[i], 1]} {names[numbers[i], 2]} - {stafs[numbers[i]]}{ending}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement