Last active
February 12, 2024 10:01
-
-
Save tsk-arh/6f4221e7dea72b3101269b9f2a5d0bb0 to your computer and use it in GitHub Desktop.
ЗАДАНИЕ Поиск преступника
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
namespace ConsoleApp4 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<Criminal> criminals = new List<Criminal> { | |
new Criminal ("Петров Петр Петрович", 180, Nationalyty.Kazah, 77, false), | |
new Criminal ("Сидоров Сидор Сидорыч", 160, Nationalyty.Francuz, 88, false), | |
new Criminal ("Байден Байден Байденович", 155, Nationalyty.Pendos, 99, true), | |
new Criminal ("Лямкин Дрист Корнетыч", 172, Nationalyty.Cheh, 66, true), | |
new Criminal ("Кабздец Христофор Василич", 189, Nationalyty.Cheh, 111, false) | |
}; | |
SearchFreeCriminal(criminals); | |
Console.ReadLine(); | |
} | |
private static void SearchFreeCriminal(List<Criminal> criminals) | |
{ | |
List<Criminal> foundCriminals = new List<Criminal>(); | |
Console.WriteLine($"Введите рост"); | |
int.TryParse(Console.ReadLine(), out int hight); | |
Console.WriteLine("Введите вес"); | |
int.TryParse(Console.ReadLine(), out int weight); | |
Console.WriteLine("Введите национальность"); | |
string nationalyty = Console.ReadLine(); | |
string empty = ""; | |
if(hight > 0 && weight > 0 && nationalyty.Trim() != empty) | |
{ | |
foundCriminals = criminals.Where(criminal => criminal.IsTakenIntoCustody == false && | |
criminal.Hight == hight && criminal.Weight == weight && criminal.Nationality.ToString().ToLower() == nationalyty.ToLower()).ToList(); | |
if (foundCriminals.Any()) | |
ShowFreeCriminal(foundCriminals); | |
else | |
Console.WriteLine($"\nСовпадений по указанным параметрам не найдено"); | |
} | |
else | |
{ | |
Console.WriteLine($"Введите корректные данные"); | |
} | |
} | |
private static void ShowFreeCriminal(List<Criminal> foundCriminals) | |
{ | |
Console.WriteLine($"\nНайдено совпадений среди криминальных личностей не находящихся в заключении: {foundCriminals.Count}"); | |
foreach (var criminal in foundCriminals) | |
{ | |
Console.WriteLine($"Имя: {criminal.Name} Рост: {criminal.Hight} Вес: {criminal.Weight} Национальность: {criminal.Nationality}"); | |
} | |
} | |
} | |
enum Nationalyty | |
{ | |
Cheh, | |
Kazah, | |
Francuz, | |
Pendos | |
} | |
class Criminal | |
{ | |
public Criminal(string name, int hight, Nationalyty nationality, int weight, bool isTakenIntoCustody) | |
{ | |
Name = name; | |
Hight = hight; | |
Nationality = nationality; | |
Weight = weight; | |
IsTakenIntoCustody = isTakenIntoCustody; | |
} | |
public string Name { get; private set; } | |
public Nationalyty Nationality { get; private set; } | |
public int Weight { get; private set; } | |
public bool IsTakenIntoCustody { get; private set; } | |
public int Hight { get; private set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment