Skip to content

Instantly share code, notes, and snippets.

@Ana19997
Created October 11, 2021 19:18
Show Gist options
  • Save Ana19997/f1991664dcb95c88e56f4bedd762e2cb to your computer and use it in GitHub Desktop.
Save Ana19997/f1991664dcb95c88e56f4bedd762e2cb to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ConsoleApp11
{
class Program
{
static void Main(string[] args)
{
string[,] fullName = new string[0,3];
string[] position = new string[0];
string userInput;
bool exit = false;
int line, convertResult;
while (!exit)
{
Console.WriteLine("Выберите необходимое значение:\n" +
"1. Добавить новое досье\n" +
"2. Вывести все досье\n" +
"3. Удалить выбранное досье\n" +
"4. Поиск досье по фамилии\n" +
"exit - выход из программы\n");
userInput = Console.ReadLine();
switch (userInput)
{
case "1":
fullName = AddFile(fullName);
position = AddFile(position);
break;
case "2":
ShowFile(fullName, position);
break;
case "3":
Console.Clear();
ShowFile(fullName, position);
Console.WriteLine("Введите номер досье которое хотите удалить:");
if (Int32.TryParse(Console.ReadLine(), out convertResult) == false)
{
Console.WriteLine("Неверные данные.\n");
}
else
{
line = convertResult - 1;
if (line >= fullName.GetLength(0))
{
Console.WriteLine("Ошибка, такого досье нет.\n");
}
else
{
fullName = DeleteFile(fullName, line);
position = DeleteFile(position, line);
Console.WriteLine("Досье удалено.\n");
}
}
break;
case "4":
FindWithSurname(fullName, position);
break;
case "exit":
exit = true;
break;
default:
Console.Clear();
Console.WriteLine("Ошибка\n");
break;
}
}
}
static string[,] AddFile(string[,] addArray)
{
Console.Clear();
string[,] tempArray = new string[addArray.GetLength(0) + 1, addArray.GetLength(1)];
for (int i = 0; i < addArray.GetLength(0); i++)
{
for (int j = 0; j < addArray.GetLength(1); j++)
{
tempArray[i, j] = addArray[i, j];
}
}
Console.WriteLine("Фамилия:");
tempArray[tempArray.GetLength(0) - 1, 0] = Console.ReadLine();
Console.WriteLine("Имя:");
tempArray[tempArray.GetLength(0) - 1, 1] = Console.ReadLine();
Console.WriteLine("Отчество:");
tempArray[tempArray.GetLength(0) - 1, 2] = Console.ReadLine();
return tempArray;
}
static string[] AddFile(string[] addArrayPos)
{
string[] tempArray = new string[addArrayPos.Length + 1];
for (int i = 0; i < addArrayPos.Length; i++)
{
tempArray[i] = addArrayPos[i];
}
Console.WriteLine("Введите должность:");
tempArray[tempArray.Length - 1] = Console.ReadLine();
Console.WriteLine("Досье создано.\n");
return tempArray;
}
static void ShowFile(string[,] showFullName, string[] showPos)
{
Console.Clear();
for (int i = 0; i < showFullName.GetLength(0); i++)
{
Console.Write((i + 1) + " - ");
for (int j = 0; j < showFullName.GetLength(1); j++)
{
Console.Write(showFullName[i, j] + " ");
}
Console.WriteLine(" - " + showPos[i] + ".");
}
Console.WriteLine();
}
static string[,] DeleteFile(string[,] arrayToDelete, int line)
{
string[,] tempArray = new string[arrayToDelete.GetLength(0) - 1, arrayToDelete.GetLength(1)];
int index = 0;
for (int i = 0; i < arrayToDelete.GetLength(0); i++)
{
if (i == line)
{
continue;
}
else
{
for (int j = 0; j < arrayToDelete.GetLength(1); j++)
{
tempArray[index, j] = arrayToDelete[i, j];
}
index++;
}
}
return tempArray;
}
static string[] DeleteFile(string[] arrayToDeletePos, int line)
{
string[] tempArray = new string[arrayToDeletePos.Length - 1];
int index = 0;
for (int i = 0; i < arrayToDeletePos.Length; i++)
{
if (i == line)
{
continue;
}
else
{
tempArray[index] = arrayToDeletePos[i];
index++;
}
}
return tempArray;
}
static void FindWithSurname(string[,] arrayToFind, string[] arrayToPos)
{
string surname;
bool found = false;
Console.Clear();
Console.WriteLine("Введите фамилию:");
surname = Console.ReadLine();
for (int i = 0; i < arrayToFind.GetLength(0); i++)
{
if (arrayToFind[i, 0].ToLower() == surname.ToLower())
{
Console.Write(i + 1 + " - ");
for (int j = 0; j < arrayToFind.GetLength(1); j++)
{
Console.Write(arrayToFind[i, j] + " ");
}
Console.WriteLine(" - " + arrayToPos[i] + ".");
found = true;
}
}
if (!found)
{
Console.WriteLine("Такая фамилия не найдена.");
}
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment