Anonim_999

SearchCriminal

Nov 2nd, 2021 (edited)
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Threading;
  4. using System.Linq;
  5.  
  6. namespace ConsoleApp2
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<Person> criminals = new List<Person>
  13.             {
  14.                 new Person("Игорь","Табуретка","Александрович",true),
  15.                 new Person("Алексей","Коволенко","Николаевич",false),
  16.                 new Person("Наталия","Яюниор","Романовна",false),
  17.                 new Person("Виктория","Бондарь","Олеговна",true)
  18.             };
  19.  
  20.             foreach (var criminal in criminals)
  21.             {
  22.                 criminal.ShowInfo();
  23.             }
  24.             Console.WriteLine("Введите рост подозреваемого: ");
  25.             int height;
  26.             int weight;
  27.             string userInputHeight = Console.ReadLine();
  28.             Console.WriteLine("Введите вес подозреваемого: ");
  29.             string userInputWeight = Console.ReadLine();
  30.             Console.WriteLine("Введите национальность подозреваемого: ");
  31.             string userInputNationality = Console.ReadLine();
  32.  
  33.             if (int.TryParse(userInputHeight, out height) && int.TryParse(userInputWeight, out weight))
  34.             {
  35.                 var suspects = criminals.Where(suspect => suspect.Height == height && suspect.Prisoner != true && suspect.Weight == weight && suspect.Nationality == userInputNationality);
  36.                 Console.Clear();
  37.                 Console.WriteLine("Подозреваемые: ");
  38.  
  39.                 foreach (var suspect in suspects)
  40.                 {
  41.                     suspect.ShowInfo();
  42.                 }
  43.             }
  44.         }
  45.     }
  46.  
  47.     class Person
  48.     {
  49.         private string _name;
  50.         private string _secondName;
  51.         private string _patronymic;
  52.         public bool Prisoner { get; private set; }
  53.         public int Weight { get; private set; }
  54.         public int Height { get; private set; }
  55.         public string Nationality { get; private set; }
  56.  
  57.         public Person(string name, string secondName, string patronymic, bool prisoner)
  58.         {
  59.             Random random = new Random();
  60.             List<string> nationalities = new List<string> { "Бурят","Армян","Поляк","Русский"};
  61.             _name = name;
  62.             _secondName = secondName;
  63.             _patronymic = patronymic;
  64.             Prisoner = prisoner;
  65.             Weight = random.Next(50, 90);
  66.             Height = random.Next(160,200);
  67.             Nationality = nationalities[random.Next(0,nationalities.Count)];
  68.         }
  69.  
  70.         public void ShowInfo()
  71.         {
  72.             Console.WriteLine($"Имя: {_name} || Фамилия: {_secondName} || Отчество: {_patronymic}\nРост: {Height} см || Вес: {Weight} кг || Национальность {Nationality}\n Заключенный: {Prisoner}\n\n");
  73.         }
  74.     }
  75. }
Add Comment
Please, Sign In to add comment