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 Lessen4
- {
- class Program
- {
- static void Main(string[] args)
- {
- string[] positionAr = new string[] {"Учитель", "Руки"};
- string[] fioAr = new string[] { "Мучитель", "Базуки"};
- bool isEsc = false;
- string fio;
- string position;
- while (!isEsc)
- {
- Console.WriteLine("Вас приветствует программа Досье");
- Console.WriteLine("Введите одну из команд:\nAdd\nFind\nPrint\nExit");
- string com = Console.ReadLine();
- switch (com.ToLower())
- {
- case "add":
- Console.Write("Введите фио: ");
- fio = Console.ReadLine();
- Console.WriteLine();
- Console.Write("Введите должность: ");
- position = Console.ReadLine();
- Console.WriteLine();
- Add(ref positionAr, ref fioAr, position, fio);
- break;
- case "print":
- Print(fioAr, positionAr);
- break;
- case "find":
- Console.Write("Введите фио для поиска: ");
- Console.WriteLine();
- fio = Console.ReadLine();
- Find(ref fioAr, ref positionAr, fio);
- break;
- case "exit":
- isEsc = true;
- break;
- }
- Console.ReadKey();
- Console.Clear();
- }
- }
- static void Add(ref string[] positionAr, ref string[] fioAr, string position, string fio)
- {
- string[] tmparray = new string[positionAr.Length + 1];
- for (int i = 0; i < positionAr.Length; i++)
- {
- tmparray[i] = positionAr[i];
- }
- tmparray[tmparray.Length - 1] = position;
- positionAr = tmparray;
- string[] tmparray1 = new string[fioAr.Length + 1];
- for (int i = 0; i < fioAr.Length; i++)
- {
- tmparray1[i] = fioAr[i];
- }
- tmparray1[tmparray1.Length - 1] = fio;
- fioAr = tmparray1;
- }
- static void Print(string[] fioAr, string[] positionAr)
- {
- for (int i = 0; i < fioAr.Length; i++)
- {
- Console.Write((i + 1) + ". " + fioAr[i] + " - " + positionAr[i]);
- Console.WriteLine();
- }
- }
- static void Find(ref string[] fioAr,ref string[] positionAr, string fio)
- {
- bool finded = false;
- for(int i = 0; i < fioAr.Length; i++)
- {
- if(fioAr[i]==fio)
- {
- Console.WriteLine("Досье найдено: " + (i + 1) + ". " + fioAr[i] + " - " + positionAr[i]);
- Console.WriteLine("Хотите удалить досье? да/нет");
- string answer = Console.ReadLine();
- switch(answer.ToLower())
- {
- case "да":
- Delete(ref fioAr, ref positionAr, i);
- break;
- case "нет":
- break;
- default:
- Console.WriteLine("такой команды нет");
- break;
- }
- finded = true;
- }
- }
- if (finded == false)
- Console.WriteLine("Такого досье нет");
- }
- static void Delete(ref string[] fioAr, ref string[] positionAr, int num)
- {
- string[] tmp1 = new string[fioAr.Length - 1];
- string[] tmp2 = new string[positionAr.Length - 1];
- for (int i = num; i<fioAr.Length-1;i++)
- {
- fioAr[i] = fioAr[i + 1];
- positionAr[i] = positionAr[i + 1];
- }
- for (int i = 0; i < tmp1.Length; i++)
- {
- tmp1[i] = fioAr[i];
- tmp2[i] = positionAr[i];
- }
- fioAr = tmp1;
- positionAr = tmp2;
- Console.WriteLine("Досье №" + (num+1) + " успешно удалено");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement