Advertisement
Guest User

Untitled

a guest
Apr 3rd, 2020
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp2
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] fullName = new string[] { "Бешлиев Эдуард Юрьевич","Рико Джони" };
  14.             string[] position = new string[] { "Воин цитадели", "Мобильная пехота" };
  15.             bool exit = false;
  16.             string userinput;
  17.  
  18.             while (!exit)
  19.             {
  20.                 Console.ReadKey();
  21.                 Console.Clear();
  22.                 Console.WriteLine("Что вы желаете сделать:\n1 - Добавить новое досье\n2 - Вывести все досье\n3 - Удалить досье" +
  23.                     "\n4 - Произвести поиск досье по фамилии\n5 - выйти из программы");
  24.                 userinput = Console.ReadLine();
  25.                 switch (userinput)
  26.                 {
  27.                     case "1":
  28.                         Console.WriteLine("Введите ФИО сотрудника:");
  29.                         string namePerson = Console.ReadLine();
  30.                         Console.WriteLine("Введите должность сотрудника:");
  31.                         string positionPerson = Console.ReadLine();
  32.                         AddNewFile(ref fullName, namePerson);
  33.                         AddNewFile(ref position, positionPerson);
  34.                         break;
  35.                     case "2":
  36.                         ShowAllFiles(fullName, position);
  37.                         break;
  38.                     case "3":
  39.                         Console.WriteLine("Введите номер досье для удаления");
  40.                         int numberFileToDelete = Convert.ToInt32(Console.ReadLine()) - 1;
  41.                         DeleteFile(ref fullName, numberFileToDelete);
  42.                         DeleteFile(ref position, numberFileToDelete);
  43.                         break;
  44.                     case "4":
  45.                         Console.Write("Введите ФИО для поиска: ");
  46.                         string namePersonFind = Console.ReadLine().ToLower();
  47.                         FindFile(fullName, position, namePersonFind);
  48.                         break;
  49.                     case "5":
  50.                         exit = true;
  51.                         break;
  52.                     default:
  53.                         Console.WriteLine("Вы ввели неверную команду, попробуйте еще раз");
  54.                         break;
  55.                 }
  56.             }
  57.             Console.WriteLine("Вы вышли из программы.");
  58.         }
  59.  
  60.         static void AddNewFile(ref string[] array, string addString)
  61.         {
  62.             string[] tempArray = new string[array.Length + 1];
  63.             for (int i = 0; i < array.Length; i++)
  64.             {
  65.                 tempArray[i] = array[i];
  66.             }
  67.             tempArray[tempArray.Length - 1] = addString;
  68.             array = tempArray;
  69.         }
  70.  
  71.         static void ShowAllFiles(string[] fullName, string[] position)
  72.         {
  73.             Console.WriteLine("Список всех досье:");
  74.             for (int i = 0; i < fullName.Length; i++)
  75.             {
  76.                 Console.WriteLine($"{i + 1}. {fullName[i]} - {position[i]};");
  77.             }
  78.         }
  79.  
  80.         static void DeleteFile(ref string[] array, int numberFileToDelete)
  81.         {
  82.             bool sortOther = false;
  83.             array[numberFileToDelete] = null;
  84.             string[] tempArray = new string[array.Length - 1];
  85.             for (int i = 0; i < array.Length; i++)
  86.             {
  87.                 if (array[i] == null)
  88.                 {
  89.                     sortOther = true;
  90.                 }
  91.                 else if (sortOther)
  92.                 {
  93.                     tempArray[i - 1] = array[i];
  94.                 }
  95.                 else
  96.                 {
  97.                     tempArray[i] = array[i];
  98.                 }
  99.             }
  100.             array = tempArray;
  101.         }
  102.  
  103.         static void FindFile(string[] fullName, string[] position, string namePersonFind)
  104.         {
  105.             bool match = false;
  106.             for (int i = 0; i < fullName.Length; i++)
  107.             {
  108.                 int countMatch = 0;
  109.                 for (int j = 0; j < namePersonFind.Length; j++)
  110.                 {
  111.                     if (fullName[i].ToLower()[j] == namePersonFind[j])
  112.                     {
  113.                         countMatch++;
  114.                         continue;
  115.                     }
  116.                     break;
  117.                 }
  118.  
  119.                 if (countMatch == namePersonFind.Length)
  120.                 {
  121.                     match = true;
  122.                     Console.WriteLine($"ФИО: {fullName[i]}\nДолжность: {position[i]}\nФайл номер {i + 1}");
  123.                     break;
  124.                 }
  125.             }
  126.  
  127.             if(match == false)
  128.             {
  129.                 Console.WriteLine("Данный персонаж не найден");
  130.             }
  131.         }
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement