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 ConsoleApp2
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] fullName = new string[] { "Бешлиев Эдуард Юрьевич","Рико Джони" };
- string[] position = new string[] { "Воин цитадели", "Мобильная пехота" };
- bool exit = false;
- string userinput;
- while (!exit)
- {
- Console.ReadKey();
- Console.Clear();
- Console.WriteLine("Что вы желаете сделать:\n1 - Добавить новое досье\n2 - Вывести все досье\n3 - Удалить досье" +
- "\n4 - Произвести поиск досье по фамилии\n5 - выйти из программы");
- userinput = Console.ReadLine();
- switch (userinput)
- {
- case "1":
- Console.WriteLine("Введите ФИО сотрудника:");
- string namePerson = Console.ReadLine();
- Console.WriteLine("Введите должность сотрудника:");
- string positionPerson = Console.ReadLine();
- AddNewFile(ref fullName, namePerson);
- AddNewFile(ref position, positionPerson);
- break;
- case "2":
- ShowAllFiles(fullName, position);
- break;
- case "3":
- Console.WriteLine("Введите номер досье для удаления");
- int numberFileToDelete = Convert.ToInt32(Console.ReadLine()) - 1;
- DeleteFile(ref fullName, numberFileToDelete);
- DeleteFile(ref position, numberFileToDelete);
- break;
- case "4":
- Console.Write("Введите ФИО для поиска: ");
- string namePersonFind = Console.ReadLine().ToLower();
- FindFile(fullName, position, namePersonFind);
- break;
- case "5":
- exit = true;
- break;
- default:
- Console.WriteLine("Вы ввели неверную команду, попробуйте еще раз");
- break;
- }
- }
- Console.WriteLine("Вы вышли из программы.");
- }
- static void AddNewFile(ref string[] array, string addString)
- {
- string[] tempArray = new string[array.Length + 1];
- for (int i = 0; i < array.Length; i++)
- {
- tempArray[i] = array[i];
- }
- tempArray[tempArray.Length - 1] = addString;
- array = tempArray;
- }
- static void ShowAllFiles(string[] fullName, string[] position)
- {
- Console.WriteLine("Список всех досье:");
- for (int i = 0; i < fullName.Length; i++)
- {
- Console.WriteLine($"{i + 1}. {fullName[i]} - {position[i]};");
- }
- }
- static void DeleteFile(ref string[] array, int numberFileToDelete)
- {
- bool sortOther = false;
- array[numberFileToDelete] = null;
- string[] tempArray = new string[array.Length - 1];
- for (int i = 0; i < array.Length; i++)
- {
- if (array[i] == null)
- {
- sortOther = true;
- }
- else if (sortOther)
- {
- tempArray[i - 1] = array[i];
- }
- else
- {
- tempArray[i] = array[i];
- }
- }
- array = tempArray;
- }
- static void FindFile(string[] fullName, string[] position, string namePersonFind)
- {
- bool match = false;
- for (int i = 0; i < fullName.Length; i++)
- {
- int countMatch = 0;
- for (int j = 0; j < namePersonFind.Length; j++)
- {
- if (fullName[i].ToLower()[j] == namePersonFind[j])
- {
- countMatch++;
- continue;
- }
- break;
- }
- if (countMatch == namePersonFind.Length)
- {
- match = true;
- Console.WriteLine($"ФИО: {fullName[i]}\nДолжность: {position[i]}\nФайл номер {i + 1}");
- break;
- }
- }
- if(match == false)
- {
- Console.WriteLine("Данный персонаж не найден");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement