Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- public class StartUp
- {
- static List<Trainer> trainers;
- public static void Main()
- {
- trainers = new List<Trainer>();
- AddTrainers();
- CheckPokemons();
- PrintTrainers();
- }
- private static void PrintTrainers()
- {
- foreach (var t in trainers.OrderByDescending(t => t.Badges))
- {
- Console.WriteLine($"{t.Name} {t.Badges} {t.Pokemons.Count}");
- }
- }
- private static void CheckPokemons()
- {
- string element;
- while ((element = Console.ReadLine()) != "End")
- {
- foreach (var trainer in trainers)
- {
- if (trainer.Pokemons.Count(p => p.Element == element) > 0)
- {
- trainer.Badges++;
- }
- else
- {
- trainer.Pokemons.Select(p => p.Health -= 10).ToList();
- trainer.Pokemons.RemoveAll(p => p.Health <= 0);
- }
- }
- }
- }
- private static void AddTrainers()
- {
- string input;
- while ((input = Console.ReadLine()) != "Tournament")
- {
- string[] args = input.Split();
- string trainerName = args[0];
- string pokemonName = args[1];
- string pokemonElement = args[2];
- int pokemonHealth = int.Parse(args[3]);
- Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
- Trainer trainer = trainers.FirstOrDefault(t => t.Name == trainerName);
- if (trainer == null)
- {
- trainer = new Trainer(trainerName);
- trainers.Add(trainer);
- }
- trainer.Pokemons.Add(pokemon);
- }
- }
- }
- //////////////////
- public class Pokemon
- {
- public Pokemon(string name, string element, int health)
- {
- this.Name = name;
- this.Element = element;
- this.Health = health;
- }
- public string Name { get; set; }
- public string Element { get; set; }
- public int Health { get; set; }
- }
- //////////////////
- using System.Collections.Generic;
- public class Trainer
- {
- public Trainer(string name)
- {
- this.Name = name;
- }
- public string Name { get; set; }
- public int Badges { get; set; } = 0;
- public List<Pokemon> Pokemons { get; set; } = new List<Pokemon>();
- }
Advertisement
Add Comment
Please, Sign In to add comment