Last active
February 12, 2024 14:48
-
-
Save tsk-arh/c080808555027db0a6918740922b03d3 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; | |
using System.Runtime.Remoting.Metadata.W3cXsd2001; | |
namespace ConsoleApp4 | |
{ | |
internal class Program | |
{ | |
static void Main(string[] args) | |
{ | |
List<Player> players = new List<Player> { | |
new Player ("Петров Петр Петрович", 22, 111), | |
new Player ("Сидоров Сидор Сидорыч", 33, 399), | |
new Player ("Байден Байден Байденович", 99, 644), | |
new Player ("Лямкин Дрист Корнетыч", 44, 777), | |
new Player ("Кабздец Христофор Василич", 55, 234), | |
new Player ("Гусь Чур Федотыч", 21, 563), | |
new Player ("Тяпкин Лопат Копайтич", 48, 972), | |
new Player ("Рябинин Ранетка Василич", 34, 638), | |
new Player ("Жмотин Жил Зажильевич", 62, 243), | |
new Player ("Корявкин Писака Картофелич", 78, 499), | |
}; | |
int countTopPosition = 3; | |
var topLevel = players.OrderByDescending(player => player.Level).Take(countTopPosition).ToList(); | |
var topForce = players.OrderByDescending(player => player.Force).Take(countTopPosition).ToList(); | |
Console.WriteLine("Топ по уровню"); | |
WritePlayers(topLevel); | |
Console.WriteLine("\nТоп по силе"); | |
WritePlayers(topForce); | |
Console.ReadLine(); | |
} | |
private static void WritePlayers(List<Player> players) | |
{ | |
for (int i = 0; i < players.Count; i++) | |
{ | |
int serialNumber = i + 1; | |
Console.WriteLine($"{serialNumber}. {players[i].Name} \nУровень: {players[i].Level} Сила: {players[i].Force}"); | |
} | |
} | |
} | |
class Player | |
{ | |
public Player(string name, int level, int force) | |
{ | |
Name = name; | |
Level = level; | |
Force = force; | |
} | |
public string Name { get; private set; } | |
public int Level { get; private set; } | |
public int Force { get; private set; } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment