Advertisement
Guest User

4.1

a guest
May 23rd, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.75 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 Lessen4
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] positionAr = new string[] {"Учитель", "Руки"};
  14.             string[] fioAr = new string[] { "Мучитель", "Базуки"};            
  15.             bool isEsc = false;
  16.             string fio;
  17.             string position;
  18.             while (!isEsc)
  19.             {
  20.  
  21.                 Console.WriteLine("Вас приветствует программа Досье");
  22.                 Console.WriteLine("Введите одну из команд:\nAdd\nFind\nPrint\nExit");
  23.                 string com = Console.ReadLine();
  24.                 switch (com.ToLower())
  25.                 {
  26.                     case "add":
  27.                         Console.Write("Введите фио: ");
  28.                         fio = Console.ReadLine();
  29.                         Console.WriteLine();
  30.                         Console.Write("Введите должность: ");
  31.                         position = Console.ReadLine();
  32.                         Console.WriteLine();
  33.                         Add(ref positionAr, ref fioAr, position, fio);
  34.                         break;
  35.                     case "print":
  36.                         Print(fioAr, positionAr);
  37.                         break;
  38.                     case "find":
  39.                         Console.Write("Введите фио для поиска: ");
  40.                         Console.WriteLine();
  41.                         fio = Console.ReadLine();
  42.                         Find(ref fioAr, ref positionAr, fio);
  43.                         break;
  44.                     case "exit":
  45.                         isEsc = true;
  46.                         break;
  47.                 }
  48.                 Console.ReadKey();
  49.                 Console.Clear();
  50.             }
  51.  
  52.         }
  53.         static void Add(ref string[] positionAr, ref string[] fioAr, string position, string fio)
  54.         {
  55.             string[] tmparray = new string[positionAr.Length + 1];
  56.             for (int i = 0; i < positionAr.Length; i++)
  57.             {
  58.                 tmparray[i] = positionAr[i];
  59.             }
  60.             tmparray[tmparray.Length - 1] = position;
  61.             positionAr = tmparray;
  62.  
  63.             string[] tmparray1 = new string[fioAr.Length + 1];
  64.             for (int i = 0; i < fioAr.Length; i++)
  65.             {
  66.                 tmparray1[i] = fioAr[i];
  67.             }
  68.             tmparray1[tmparray1.Length - 1] = fio;
  69.             fioAr = tmparray1;
  70.         }
  71.         static void Print(string[] fioAr, string[] positionAr)
  72.         {
  73.             for (int i = 0; i < fioAr.Length; i++)
  74.             {
  75.                 Console.Write((i + 1) + ". " + fioAr[i] + " - " + positionAr[i]);
  76.                 Console.WriteLine();
  77.             }
  78.         }
  79.         static void Find(ref string[] fioAr,ref string[] positionAr, string fio)
  80.         {
  81.             bool finded = false;
  82.             for(int i = 0; i < fioAr.Length; i++)
  83.             {
  84.                 if(fioAr[i]==fio)
  85.                 {
  86.                     Console.WriteLine("Досье найдено: " + (i + 1) + ". " + fioAr[i] + " - " + positionAr[i]);
  87.                     Console.WriteLine("Хотите удалить досье? да/нет");
  88.                     string answer = Console.ReadLine();
  89.                     switch(answer.ToLower())
  90.                     {
  91.                         case "да":
  92.                             Delete(ref fioAr, ref positionAr, i);
  93.                             break;
  94.                         case "нет":
  95.                             break;
  96.                         default:
  97.                             Console.WriteLine("такой команды нет");
  98.                             break;
  99.                     }
  100.                     finded = true;
  101.                 }
  102.  
  103.             }
  104.             if (finded == false)
  105.                 Console.WriteLine("Такого досье нет");
  106.  
  107.         }
  108.         static void Delete(ref string[] fioAr, ref string[] positionAr, int num)
  109.         {
  110.             string[] tmp1 = new string[fioAr.Length - 1];
  111.             string[] tmp2 = new string[positionAr.Length - 1];
  112.             for (int i = num; i<fioAr.Length-1;i++)
  113.             {
  114.                 fioAr[i] = fioAr[i + 1];
  115.                 positionAr[i] = positionAr[i + 1];
  116.             }
  117.             for (int i = 0; i < tmp1.Length; i++)
  118.             {
  119.                 tmp1[i] = fioAr[i];
  120.                 tmp2[i] = positionAr[i];
  121.             }
  122.             fioAr = tmp1;
  123.             positionAr = tmp2;
  124.             Console.WriteLine("Досье №" + (num+1) + " успешно удалено");
  125.  
  126.         }
  127.     }
  128. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement