Skip to content

Instantly share code, notes, and snippets.

@StrikerXx798
Last active June 21, 2025 19:18
Show Gist options
  • Save StrikerXx798/a54592803bb832e7b46cd0d032bc08ca to your computer and use it in GitHub Desktop.
Save StrikerXx798/a54592803bb832e7b46cd0d032bc08ca to your computer and use it in GitHub Desktop.
ДЗ: Поиск преступника
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApp1
{
public class Program
{
static void Main(string[] args)
{
Console.InputEncoding = Encoding.Unicode;
Console.OutputEncoding = Encoding.Unicode;
DetectivePC detectivePC = new DetectivePC();
detectivePC.On();
}
}
class DetectivePC
{
private const int CommandGetFelonsByParams = 1;
private const int CommandExit = 0;
public DetectivePC()
{
_felons = new List<Felon>()
{
new Felon("Дон Карлеоне", false, 180, 90, "Итальянец"),
new Felon("Джон Смит", true, 175, 80, "Англичанин"),
new Felon("Иван Иванов", false, 182, 85, "Русский"),
new Felon("Пьер Дюпон", false, 170, 70, "Француз"),
new Felon("Карл Мюллер", true, 185, 95, "Немец"),
new Felon("Ли Чен", false, 168, 65, "Китаец"),
new Felon("Мигель Родригес", true, 178, 88, "Испанец"),
new Felon("Томас Андерсон", false, 183, 82, "Американец"),
new Felon("Ахмед Али", true, 172, 77, "Араб"),
new Felon("Сергей Петров", false, 180, 90, "Русский"),
};
}
private List<Felon> _felons;
public void On()
{
bool isOn = true;
while (isOn)
{
Console.WriteLine(
"Добро пожаловать в базу данных преступников вашего города Детектив"
);
Console.WriteLine("\nМеню:");
Console.WriteLine(
$"{CommandGetFelonsByParams} - Показать список приступников по параметрам"
);
Console.WriteLine($"{CommandExit} - Завершить работу");
int input = GetNumberInput("Введите команду: ");
switch (input)
{
case CommandGetFelonsByParams:
ShowFelonsByParams();
break;
case CommandExit:
isOn = false;
break;
default:
Console.WriteLine("Неизвестная команда.");
break;
}
}
}
private int GetNumberInput(string message)
{
Console.WriteLine(message);
string input = Console.ReadLine();
int number;
while (int.TryParse(input, out number) == false)
{
Console.WriteLine("Некорректный ввод. Попробуйте снова.");
input = Console.ReadLine();
}
return number;
}
private string GetNationalityInput()
{
Console.WriteLine("Введите нациоанальность: ");
string input = Console.ReadLine();
while (_felons.Where(felon => felon.Nationality.ToLower().Contains(input.ToLower())).ToList().Count <= 0)
{
Console.WriteLine("Такой национальности нет в списке. Попробуйте снова.");
input = Console.ReadLine();
}
return input;
}
private void ShowFelonsByParams()
{
Console.WriteLine("Укажите параметры преступников");
int height = GetNumberInput("Введите рост: ");
int weight = GetNumberInput("Введите вес: ");
string nationality = GetNationalityInput();
var filteredFalons = _felons
.Where(felon =>
felon.Height <= height
&& felon.Weight <= weight
&& felon.Nationality.Contains(nationality.ToLower())
&& felon.IsArrested == false
)
.ToList();
if (filteredFalons.Count == 0)
Console.WriteLine("По вашему запросов преступники не найдены");
Console.WriteLine();
Console.WriteLine("Список преступников по вашему запросу:");
foreach (var felon in filteredFalons)
{
felon.ShowInfo();
}
}
}
class Felon
{
public Felon(string name, bool isArrested, int height, int weight, string nationality)
{
_name = name;
IsArrested = isArrested;
Height = height;
Weight = weight;
Nationality = nationality;
}
private string _name;
public int Height { get; }
public int Weight { get; }
public string Nationality { get; }
public bool IsArrested { get; }
public void ShowInfo()
{
Console.WriteLine(
$"ФИО: {_name}\nРост: {Height}\nВес: {Weight}\nНацинальность:{Nationality}"
);
Console.WriteLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment