Advertisement
holllowknight

Топ

May 4th, 2023
924
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace top
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int playersInTop = 3;
  12.             List<Player> players = new List<Player>()
  13.             {
  14.                 new Player("Gamer3000", 80, 200),
  15.                 new Player("Jecki", 42, 100),
  16.                 new Player("Anton", 40, 125),
  17.                 new Player("Vasyan99", 5, 15),
  18.                 new Player("Ignat", 15, 33),
  19.                 new Player("Belyj", 31, 97),
  20.                 new Player("Freeman", 22, 46),
  21.                 new Player("Ivan", 21, 44),
  22.                 new Player("Leo", 66, 99),
  23.                 new Player("Ark", 65, 152),
  24.                 new Player("Regina", 79, 124),
  25.                 new Player("Lupin", 25, 71),
  26.             };
  27.  
  28.             var topLevel = players.OrderByDescending(player => player.Level).Take(playersInTop);
  29.             Console.WriteLine("Топ игроков по уровню:");
  30.             ShowPlayers(topLevel);
  31.             var topStrength = players.OrderByDescending(player => player.Strength).Take(playersInTop);
  32.             Console.WriteLine("\nТоп игроков по силе:");
  33.             ShowPlayers(topStrength);
  34.         }
  35.  
  36.         static private void ShowPlayers(IEnumerable<Player> players)
  37.         {
  38.             foreach (var player in players)
  39.                 player.ShowInfo();
  40.         }
  41.     }
  42.  
  43.     class Player
  44.     {
  45.         public Player(string nick, int level, int strength)
  46.         {
  47.             Nick = nick;
  48.             Level = level;
  49.             Strength = strength;
  50.         }
  51.  
  52.         public string Nick { get; private set; }
  53.         public int Level { get; private set; }
  54.         public int Strength { get; private set; }
  55.  
  56.         public void ShowInfo()
  57.         {
  58.             Console.WriteLine($"{Nick} уровень:{Level} сила:{Strength}");
  59.         }
  60.     }
  61. }
  62.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement