Пример #1
0
        public static void Main(string[] args)
        {
            Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();

            string inputInfo = Console.ReadLine();

            while (inputInfo != "Tournament")
            {
                string[] inputInfoArgs = inputInfo
                                         .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                string trainerName    = inputInfoArgs[0];
                string pokemonName    = inputInfoArgs[1];
                string pokemonElement = inputInfoArgs[2];
                int    pokemonHealth  = int.Parse(inputInfoArgs[3]);

                if (!trainers.ContainsKey(trainerName))
                {
                    trainers.Add(trainerName, new Trainer(trainerName));
                }

                Trainer currentTrainer = trainers[trainerName];

                //<=> currentTraine = trainers.FirstOrDefault(x => x.Key == trainer.Name).Value;

                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                currentTrainer.Pokemons.Add(pokemon);

                inputInfo = Console.ReadLine();
            }

            string command = Console.ReadLine();

            while (command != "End")
            {
                string element = command;

                foreach (var trainer in trainers)
                {
                    if (trainer.Value.Pokemons.Any(p => p.Element == element))
                    {
                        trainer.Value.NumberOfBadges++;
                    }
                    else
                    {
                        foreach (var pokemon in trainer.Value.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }

                        trainer.Value.Pokemons.RemoveAll(p => p.Health <= 0);
                    }
                }

                command = Console.ReadLine();
            }

            trainers = trainers
                       .OrderByDescending(t => t.Value.NumberOfBadges)
                       .ToDictionary(k => k.Key, v => v.Value);

            foreach (var trainer in trainers)
            {
                Console.WriteLine($"{trainer.Key} {trainer.Value.NumberOfBadges} {trainer.Value.Pokemons.Count}");
            }
        }
Пример #2
0
        public static void Main()
        {
            List <Trainer> trainers = new List <Trainer>();
            string         input;

            while ((input = Console.ReadLine()) != "Tournament")
            {
                var line = input.Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToArray();

                var trainerName    = line[0];
                var pokemonName    = line[1];
                var pokemonElement = line[2];
                var pokemonHealth  = int.Parse(line[3]);

                if (!trainers.Any(t => t.Name == trainerName))
                {
                    var trainer = new Trainer(trainerName);
                    trainers.Add(trainer);
                    var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                    trainer.AddPokemon(pokemon);
                }
                else
                {
                    var existingTrainer = trainers.FirstOrDefault(t => t.Name == trainerName);
                    var pokemon         = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                    existingTrainer.AddPokemon(pokemon);
                }
            }
            string secondInput;

            while ((secondInput = Console.ReadLine()) != "End")
            {
                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Any(p => p.Element == secondInput))
                    {
                        trainer.NumberOfBadges += 1;
                    }
                    else
                    {
                        trainer.PokemonsLoseHealth();
                    }
                }
            }

            var orderedTrainers = trainers
                                  .OrderByDescending(t => t.NumberOfBadges)
                                  .ToList();

            foreach (var trainer in orderedTrainers)
            {
                Console.WriteLine(trainer.Name + " " + trainer.NumberOfBadges + " " + trainer.Pokemons.Count);
            }

            //var tr = orderedTrainers.FirstOrDefault(t => t.Name == "Pesho");
            //var pokemons = tr.Pokemons;
            //var info = pokemons.GroupBy(p => p.Element).ToList()
            //    .OrderBy(p => p.Key);

            //foreach (var item in info)
            //{
            //    Console.WriteLine(item.Key);
            //    foreach (var val in item.OrderBy(p => p.Name))
            //    {
            //        Console.WriteLine(val.Name);
            //    }
            //}

            var firstPokemons  = trainers.SelectMany(t => t.Pokemons).ToList();
            var secondPokemons = trainers.Select(t => t.Pokemons).ToList();

            foreach (var item in firstPokemons)
            {
                Console.WriteLine(item.Name);
            }

            foreach (var item in secondPokemons)
            {
                foreach (var p in item)
                {
                    Console.WriteLine(p.Name);
                }
            }
            ;
        }
Пример #3
0
 public void AddTrainer(Trainer trainer)
 {
     this.trainers.Add(trainer);
 }
Пример #4
0
        static void Main(string[] args)
        {
            List <Trainer> trainers = new List <Trainer>();

            string input = Console.ReadLine();

            while (input != "Tournament")
            {
                string[] data           = input.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   trainerName    = data[0];
                string   pokemonName    = data[1];
                string   pokemonElement = data[2];
                int      health         = int.Parse(data[3]);

                bool doesExist = false;

                Pokemon pokemon = CreatePokemon(pokemonName, pokemonElement, health);

                foreach (Trainer trainer in trainers)
                {
                    if (trainer.Name == trainerName)
                    {
                        trainer.AddPokemon(pokemon);
                        doesExist = true;
                        break;
                    }
                }

                if (!doesExist)
                {
                    Trainer currentTrainer = new Trainer(trainerName);
                    trainers.Add(currentTrainer);
                    currentTrainer.AddPokemon(pokemon);
                }

                input = Console.ReadLine();
            }

            string element = Console.ReadLine();

            while (element != "End")
            {
                foreach (Trainer trainer in trainers)
                {
                    if (trainer.Pokemons.Any(p => p.Element == element))
                    {
                        trainer.Badges++;
                    }
                    else
                    {
                        for (int i = 0; i < trainer.Pokemons.Count; i++)
                        {
                            if (trainer.Pokemons[i].Name != element)
                            {
                                trainer.Pokemons[i].Health -= 10;

                                if (trainer.Pokemons[i].Health <= 0)
                                {
                                    trainer.Pokemons.Remove(trainer.Pokemons[i]);
                                    i--;
                                }
                            }
                        }
                    }
                }

                element = Console.ReadLine();
            }

            foreach (Trainer trainer in trainers.OrderByDescending(t => t.Badges))
            {
                Console.WriteLine(trainer);
            }
        }
Пример #5
0
        public static void Main(string[] args)
        {
            var pokemons = new List <Pokemon>();
            var trainers = new Dictionary <string, Trainer>();

            var inputLine = Console.ReadLine();

            while (inputLine != "Tournament")
            {
                var inputInfo = inputLine
                                .Split(" ", StringSplitOptions.RemoveEmptyEntries);

                var trainerName    = inputInfo[0];
                var pokemonName    = inputInfo[1];
                var pokemonElement = inputInfo[2];
                var pokemonHealth  = int.Parse(inputInfo[3]);


                var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (!trainers.ContainsKey(trainerName))
                {
                    trainers[trainerName] = new Trainer(trainerName);
                }
                trainers[trainerName].Pokemons.Add(pokemon);

                inputLine = Console.ReadLine();
            }

            inputLine = Console.ReadLine();

            while (inputLine != "End")
            {
                var pokemonElement = inputLine;


                foreach (var(currentTrainer, trainerStats) in trainers)
                {
                    if (trainerStats.Pokemons.Any(p => p.Element == pokemonElement))
                    {
                        trainerStats.NumberOfBadges++;
                    }
                    else
                    {
                        foreach (var pokemon in trainerStats.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }

                        trainerStats.Pokemons.RemoveAll(h => h.Health <= 0);
                    }
                }

                inputLine = Console.ReadLine();
            }

            trainers = trainers
                       .OrderByDescending(v => v.Value.NumberOfBadges)
                       .ToDictionary(k => k.Key, v => v.Value);

            foreach (var trainer in trainers)
            {
                Console.WriteLine($"{trainer.Key} {trainer.Value.NumberOfBadges} {trainer.Value.Pokemons.Count}");
            }
        }
Пример #6
0
        static void Main(string[] args)
        {
            //var pesho = new Person("Pesho", 28);
            //var gosho = new Person("Gosho", 18);
            //var stamat = new Person("Stamat", 43);

            //var testPerson = new Person();

            //Console.WriteLine(testPerson.Name + " " + testPerson.Age);

            //var testPerson2 = new Person(25);

            //Console.WriteLine(testPerson2.Name + " " + testPerson2.Age);

            //int n = int.Parse(Console.ReadLine());
            //var family = new Family();

            //for (int i = 0; i < n; i++)
            //{
            //    string[] input = Console.ReadLine().Split();

            //    var person = new Person(input[0], int.Parse(input[1]));

            //    family.AddMember(person);
            //}

            //var oldestMember = family.GetOldestMember();

            //Console.WriteLine(oldestMember.Name + " " + oldestMember.Age);

            //int n = int.Parse(Console.ReadLine());
            //var people = new List<Person>();

            //for (int i = 0; i < n; i++)
            //{
            //    string[] input = Console.ReadLine().Split();

            //    var person = new Person(input[0], int.Parse(input[1]));
            //    people.Add(person);
            //}

            //var peopleOver30 = people.OrderBy(p => p.Name).Where(p => p.Age > 30);

            //foreach (var person in peopleOver30)
            //{
            //    Console.WriteLine($"{person.Name} - {person.Age}");
            //}

            //var firstDate = Console.ReadLine();
            //var secondDate = Console.ReadLine();
            //Console.WriteLine(DateModifier.GetDaysBetweenDates(firstDate, secondDate));

            //var employees = GetEmployees();
            //PrintEmployeesWithHighestSalary(employees);


            //int n = int.Parse(Console.ReadLine());
            //var cars = new List<Car>();

            //for (int i = 0; i < n; i++)
            //{
            //    string[] inputParts = Console.ReadLine().Split();

            //    string model = inputParts[0];
            //    double fuelAmount = double.Parse(inputParts[1]);
            //    double fuelConsumptionPerKm = double.Parse(inputParts[2]);

            //    var car = new Car(model, fuelAmount, fuelConsumptionPerKm, 0);
            //    cars.Add(car);
            //}

            //string command = Console.ReadLine();

            //while (command != "End")
            //{
            //    string[] tokens = command.Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            //    string model = tokens[1];
            //    double distance = double.Parse(tokens[2]);

            //    cars.Where(c => c.Model == model).ToList().ForEach(c => c.Drive(distance));

            //    command = Console.ReadLine();
            //}

            //foreach (var car in cars)
            //{
            //    Console.WriteLine($"{car.Model} {car.FuelAmount:f2} {car.TravelledDistance}");
            //}

            //int n = int.Parse(Console.ReadLine());
            //var cars = new List<Car>();

            //for (int i = 0; i < n; i++)
            //{
            //    string[] input = Console.ReadLine().Split();

            //    string model = input[0];
            //    int engineSpeed = int.Parse(input[1]);
            //    int enginePower = int.Parse(input[2]);
            //    int cargoWeight = int.Parse(input[3]);
            //    string cargoType = input[4];
            //    double tire1Pressure = double.Parse(input[5]);
            //    int tire1Age = int.Parse(input[6]);
            //    double tire2Pressure = double.Parse(input[7]);
            //    int tire2Age = int.Parse(input[8]);
            //    double tire3Pressure = double.Parse(input[9]);
            //    int tire3Age = int.Parse(input[10]);
            //    double tire4Pressure = double.Parse(input[11]);
            //    int tire4Age = int.Parse(input[12]);

            //    var engine = new Engine(engineSpeed, enginePower);
            //    var cargo = new Cargo(cargoWeight, cargoType);
            //    var tires = new Tire[4]
            //    {
            //        new Tire(tire1Age, tire1Pressure),
            //        new Tire(tire2Age, tire2Pressure),
            //        new Tire(tire3Age, tire3Pressure),
            //        new Tire(tire4Age, tire4Pressure)
            //    };
            //    var car = new Car(model, engine, cargo, tires);
            //    cars.Add(car);
            //}

            //string command = Console.ReadLine();

            //if (command == "fragile")
            //{
            //    cars
            //        .Where(c => c.Cargo.Type == "fragile")
            //        .Where(c => c.Tires.Any(t => t.Pressure < 1))
            //        .ToList()
            //        .ForEach(x => Console.WriteLine(x.Model));
            //}
            //else if (command == "flamable")
            //{
            //    cars
            //        .Where(c => c.Cargo.Type == "flamable")
            //        .Where(c => c.Engine.Power > 250)
            //        .ToList()
            //        .ForEach(x => Console.WriteLine(x.Model));
            //}


            //int n = int.Parse(Console.ReadLine());
            //var engines = new List<Engine>();

            //for (int i = 0; i < n; i++)
            //{
            //    string[] tokens = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            //    string model = tokens[0];
            //    string power = tokens[1];

            //    if (tokens.Length == 2)
            //    {
            //        engines.Add(new Engine(model, power));
            //    }
            //    else if (tokens.Length == 3)
            //    {
            //        int displacement;
            //        bool isDisplacement = int.TryParse(tokens[2], out displacement);
            //        if (isDisplacement)
            //        {
            //            engines.Add(new Engine(model, power, displacement));
            //        }
            //        else
            //        {
            //            string efficiency = tokens[2];
            //            engines.Add(new Engine(model, power, efficiency));
            //        }
            //    }
            //    else if (tokens.Length == 4)
            //    {
            //        int displacement = int.Parse(tokens[2]);
            //        string efficiency = tokens[3];
            //        engines.Add(new Engine(model, power, displacement, efficiency));
            //    }
            //}

            //int carsCount = int.Parse(Console.ReadLine());
            //List<Car> cars = new List<Car>();

            //for (int i = 0; i < carsCount; i++)
            //{
            //    string[] tokens = Console.ReadLine().Split(new char[0], StringSplitOptions.RemoveEmptyEntries);
            //    string model = tokens[0];
            //    string engineModel = tokens[1];
            //    Engine engine = new Engine(null, null);

            //    foreach (Engine eng in engines)
            //    {
            //        if (eng.Model == engineModel)
            //        {
            //            engine = eng;
            //        }
            //    }

            //    if (tokens.Length == 2)
            //    {
            //        cars.Add(new Car(model, engine));
            //    }
            //    else if (tokens.Length == 3)
            //    {
            //        int weight;
            //        bool isWeight = int.TryParse(tokens[2], out weight);
            //        if (isWeight)
            //        {
            //            cars.Add(new Car(model, engine, weight));
            //        }
            //        else
            //        {
            //            string color = tokens[2];
            //            cars.Add(new Car(model, engine, color));
            //        }
            //    }
            //    else if (tokens.Length == 4)
            //    {
            //        int weight = int.Parse(tokens[2]);
            //        string color = tokens[3];
            //        cars.Add(new Car(model, engine, weight, color));
            //    }
            //}

            //foreach (Car car in cars)
            //{
            //    Console.WriteLine("{0}:", car.Model);
            //    Console.WriteLine("  {0}:", car.Engine.Model);
            //    Console.WriteLine("    Power: {0}", car.Engine.Power);
            //    Console.WriteLine("    Displacement: {0}", car.Engine.Displacement == 0 ? "n/a" : car.Engine.Displacement.ToString());
            //    Console.WriteLine("    Efficiency: {0}", car.Engine.Efficiency);
            //    Console.WriteLine("  Weight: {0}", car.Weight == 0 ? "n/a" : car.Weight.ToString());
            //    Console.WriteLine("  Color: {0}", car.Color);
            //}

            var    trainers = new List <Trainer>();
            string command  = Console.ReadLine();

            while (command != "Tournament")
            {
                string[] commandParts = command.Split();

                string trainerName    = commandParts[0];
                string pokemonName    = commandParts[1];
                string pokemonElement = commandParts[2];
                int    pokemonHealth  = int.Parse(commandParts[3]);

                var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (!trainers.Any(tn => tn.Name == trainerName))
                {
                    var trainer = new Trainer(trainerName, 0, new List <Pokemon>());
                    trainers.Add(trainer);
                }

                trainers.Find(tn => tn.Name == trainerName).Pokemons.Add(pokemon);

                command = Console.ReadLine();
            }

            string command2 = Console.ReadLine();

            while (command2 != "End")
            {
                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Any(p => p.Element == command2))
                    {
                        trainer.Badges++;
                    }
                    else
                    {
                        for (int i = 0; i < trainer.Pokemons.Count; i++)
                        {
                            trainer.Pokemons[i].Health -= 10;
                            if (trainer.Pokemons[i].Health <= 0)
                            {
                                trainer.Pokemons.RemoveAt(i);
                            }
                        }
                    }
                }

                command2 = Console.ReadLine();
            }

            foreach (var trainer in trainers.OrderByDescending(b => b.Badges))
            {
                Console.WriteLine($"{trainer.Name} {trainer.Badges} {trainer.Pokemons.Count}");
            }
        }
Пример #7
0
        public static void Main()
        {
            // task 1 and 2
            //var pesho = new Person(30, "Pesho");
            //var stamat = new Person(31, "Stamat");

            //List<Person> persons = new List<Person>()
            //{
            //    pesho,
            //    new Person(35, "Gosho"),
            //    stamat
            //};

            // var p = new Person();
            // var p = new Person(35);
            //var p = new Person(37, "Joro");
            //Console.WriteLine(p.Name);
            //Console.WriteLine(p.Age);

            // task 3
            //int N = int.Parse(Console.ReadLine());
            //var family = new Family();
            //for (int i = 0; i < N; i++)
            //{
            //    string[] args = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            //    var person = new Person(int.Parse(args[1]), args[0]);
            //    family.AddMember(person);
            //}

            //var oldest = family.GetOldestMember();
            //Console.WriteLine($"{oldest.Name} {oldest.Age}");

            // task 4
            //int N = int.Parse(Console.ReadLine());
            //List<Person> people = new List<Person>();
            //for (int i = 0; i < N; i++)
            //{
            //    string[] args = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            //    var person = new Person(int.Parse(args[1]), args[0]);
            //    people.Add(person);
            //}

            //var ordered = people
            //                .Where(p => p.Age > 30)
            //                .OrderBy(p => p.Name)
            //                .ToList();

            //ordered.ForEach(p => Console.WriteLine($"{p.Name} - {p.Age}"));

            // task 5
            //string date = Console.ReadLine();
            //string otherDate = Console.ReadLine();
            //int daysDiff = DateModifier.CalculateDifference(date, otherDate);
            //Console.WriteLine(daysDiff);

            // task 6
            //int N = int.Parse(Console.ReadLine());
            //List<Car> cars = new List<Car>();
            //for (int i = 0; i < N; i++)
            //{
            //    string[] carInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            //    string model = carInfo[0];
            //    double fuelAmount = double.Parse(carInfo[1]);
            //    double fuelConsumption = double.Parse(carInfo[2]);

            //    var car = new Car(model, fuelAmount, fuelConsumption);
            //    cars.Add(car);
            //}

            //while (true)
            //{
            //    string cmd = Console.ReadLine();
            //    if (cmd == "End")
            //    {
            //        break;
            //    }

            //    string[] cmdArgs = cmd.Split(' ', StringSplitOptions.RemoveEmptyEntries);
            //    string carModel = cmdArgs[1];
            //    double distance = double.Parse(cmdArgs[2]);

            //    cars.FirstOrDefault(c => c.Model == carModel).Drive(distance);
            //}

            //cars.ForEach(c => Console.WriteLine($"{c.Model} {c.FuelAmount:F2} {c.TravelledDistance}"));

            // task 7
            //int N = int.Parse(Console.ReadLine());
            //List<Car> cars = new List<Car>();
            //for (int i = 0; i < N; i++)
            //{
            //    string[] carInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

            //    string model = carInfo[0];
            //    int engineSpeed = int.Parse(carInfo[1]);
            //    int enginePower = int.Parse(carInfo[2]);
            //    int cargoWeight = int.Parse(carInfo[3]);
            //    string cargoType = carInfo[4];
            //    double tire1Pressure = double.Parse(carInfo[5]);
            //    int tire1Age = int.Parse(carInfo[6]);
            //    double tire2Pressure = double.Parse(carInfo[7]);
            //    int tire2Age = int.Parse(carInfo[8]);
            //    double tire3Pressure = double.Parse(carInfo[9]);
            //    int tire3Age = int.Parse(carInfo[10]);
            //    double tire4Pressure = double.Parse(carInfo[11]);
            //    int tire4Age = int.Parse(carInfo[12]);

            //    var engine = new Engine(engineSpeed, enginePower);
            //    var cargo = new Cargo(cargoWeight, cargoType);
            //    var tires = new Tire[]
            //    {
            //        new Tire(tire1Age, tire1Pressure),
            //        new Tire(tire2Age, tire2Pressure),
            //        new Tire(tire3Age, tire3Pressure),
            //        new Tire(tire4Age, tire4Pressure)
            //    };

            //    var car = new Car(model, engine, cargo, tires);
            //    cars.Add(car);
            //}

            //string filter = Console.ReadLine();
            //switch (filter)
            //{
            //    case "fragile":
            //        cars
            //            .Where(c => c.Cargo.Type == filter)
            //            .Where(c => c.Tires.Any(t => t.Preasure < 1))
            //            .ToList()
            //            .ForEach(c => Console.WriteLine(c.Model));
            //        break;
            //    case "flamable":
            //        cars
            //            .Where(c => c.Cargo.Type == filter)
            //            .Where(c => c.Engine.Power > 250)
            //            .ToList()
            //            .ForEach(c => Console.WriteLine(c.Model));
            //        break;
            //}

            // task 8
            //int N = int.Parse(Console.ReadLine());
            //List<Engine> engines = new List<Engine>();
            //for (int i = 0; i < N; i++)
            //{
            //    string[] engineInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);

            //    var engine = new Engine(engineInfo[0], int.Parse(engineInfo[1]));
            //    switch (engineInfo.Length)
            //    {
            //        case 3:
            //            if (int.TryParse(engineInfo[2], out int displacement))
            //            {
            //                engine.Displacement = displacement;
            //            }
            //            else
            //            {
            //                engine.Efficiency = engineInfo[2];
            //            }

            //            break;
            //        case 4:
            //            engine.Displacement = int.Parse(engineInfo[2]);
            //            engine.Efficiency = engineInfo[3];
            //            break;
            //    }

            //    engines.Add(engine);
            //}

            //int M = int.Parse(Console.ReadLine());
            //List<Car> cars = new List<Car>();
            //for (int i = 0; i < M; i++)
            //{
            //    string[] carInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
            //    string model = carInfo[0];
            //    string engineModel = carInfo[1];

            //    var engine = engines.First(e => e.Model == engineModel);
            //    var car = new Car(model, engine);
            //    switch (carInfo.Length)
            //    {
            //        case 3:
            //            if (int.TryParse(carInfo[2], out int weight))
            //            {
            //                car.Weight = weight;
            //            }
            //            else
            //            {
            //                car.Color = carInfo[2];
            //            }

            //            break;
            //        case 4:
            //            car.Weight = int.Parse(carInfo[2]);
            //            car.Color = carInfo[3];
            //            break;
            //    }

            //    cars.Add(car);
            //}

            //cars.ForEach(Console.WriteLine);

            // task 9
            List <Trainer> trainers = new List <Trainer>();

            while (true)
            {
                string[] pokemonInfo = Console.ReadLine().Split(' ', StringSplitOptions.RemoveEmptyEntries);
                if (pokemonInfo[0] == "Tournament")
                {
                    break;
                }

                string trainerName    = pokemonInfo[0];
                string pokemonName    = pokemonInfo[1];
                string pokemonElement = pokemonInfo[2];
                int    pokemonHealth  = int.Parse(pokemonInfo[3]);

                var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                var trainer = new Trainer(trainerName, new List <Pokemon>()
                {
                    pokemon
                });

                int trainerIndex = trainers.FindIndex(tr => tr.Name == trainerName);
                if (trainerIndex != -1)
                {
                    trainers[trainerIndex].Pokemons.Add(pokemon);
                }
                else
                {
                    trainers.Add(trainer);
                }
            }

            while (true)
            {
                string element = Console.ReadLine();
                if (element == "End")
                {
                    break;
                }

                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Any(p => p.Element == element))
                    {
                        trainer.Badges++;
                    }
                    else
                    {
                        trainer.Pokemons.ForEach(p => p.Health -= 10);
                        trainer.Pokemons.RemoveAll(p => p.Health <= 0);
                    }
                }
            }

            var ordered = trainers.OrderByDescending(tr => tr.Badges).ToList();

            ordered.ForEach(tr => Console.WriteLine($"{tr.Name} {tr.Badges} {tr.Pokemons.Count}"));
        }
Пример #8
0
        static void Main(string[] args)
        {
            string command = Console.ReadLine();
            Dictionary <string, Trainer> trainers = new Dictionary <string, Trainer>();


            while (command != "Tournament")
            {
                string[] input          = command.Split(' ', StringSplitOptions.RemoveEmptyEntries);
                string   trainerName    = input[0];
                string   pokemonName    = input[1];
                string   pokemonElement = input[2];
                int      pokemonHealth  = int.Parse(input[3]);


                if (!trainers.ContainsKey(trainerName))
                {
                    trainers[trainerName] = new Trainer(trainerName);
                }


                Pokemon pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);
                trainers[trainerName].Pokemons.Add(pokemon);



                command = Console.ReadLine();
            }

            //foreach (var item in trainers)
            //{
            //    Console.WriteLine(item.Value.Name);
            //    Console.WriteLine(item.Value.Badges);
            //    foreach (var pokemon in item.Value.Pokemons)
            //    {
            //        Console.WriteLine($"-{pokemon.Name} {pokemon.Element} {pokemon.Health}");
            //    }
            //}
            string element = Console.ReadLine();

            while (element != "End")
            {
                foreach (var trainer in trainers)
                {
                    if (trainer.Value.Pokemons.Any(x => x.Element == element))
                    {
                        trainer.Value.Badges++;
                    }
                    else
                    {
                        foreach (var pokemon in trainer.Value.Pokemons)
                        {
                            pokemon.Health -= 10;
                        }
                    }
                    trainer.Value.Pokemons.RemoveAll(x => x.Health <= 0);
                }



                //foreach (var item in trainers)
                //{
                //    Console.WriteLine(item.Value.Name);
                //    Console.WriteLine(item.Value.Badges);
                //    foreach (var pokemon in item.Value.Pokemons)
                //    {
                //        Console.WriteLine($"-{pokemon.Name} {pokemon.Element} {pokemon.Health}");
                //    }
                //}

                element = Console.ReadLine();
            }
            var sortedTrainers = trainers.OrderByDescending(x => x.Value.Badges);

            foreach (var item in sortedTrainers)
            {
                Console.WriteLine($"{item.Value.Name} {item.Value.Badges} {item.Value.Pokemons.Count}");
            }
        }
        public static void Main()
        {
            var trainers = new HashSet <Trainer>();

            while (true)
            {
                var inputArgs = Console.ReadLine()
                                .Split(" ");

                if (inputArgs[0] == "Tournament")
                {
                    break;
                }

                var trainerName    = inputArgs[0];
                var pokemonName    = inputArgs[1];
                var pokemonElement = inputArgs[2];
                var pokemonHealth  = int.Parse(inputArgs[3]);

                var pokemon = new Pokemon(pokemonName, pokemonElement, pokemonHealth);

                if (!trainers.Any(x => x.Name == trainerName))
                {
                    var pokemons = new List <Pokemon>();
                    pokemons.Add(pokemon);

                    var trainer = new Trainer(trainerName, 0, pokemons);
                    trainers.Add(trainer);
                }
                else
                {
                    var trainer = trainers.FirstOrDefault(x => x.Name == trainerName);
                    trainer.Pokemons.Add(pokemon);
                }
            }

            while (true)
            {
                var inputArgs = Console.ReadLine()
                                .Split(" ");

                if (inputArgs[0] == "End")
                {
                    break;
                }

                var element = inputArgs[0];

                foreach (var trainer in trainers)
                {
                    if (trainer.Pokemons.Any(x => x.Element == element))
                    {
                        trainer.Badges++;
                    }
                    else
                    {
                        trainer.Pokemons
                        .Select(x => x.Health -= 10)
                        .ToList();

                        trainer.Pokemons = trainer.Pokemons
                                           .Where(x => x.Health > 0)
                                           .ToList();
                    }
                }
            }

            trainers = trainers
                       .OrderByDescending(x => x.Badges)
                       .ToHashSet();

            Console.WriteLine(String.Join(Environment.NewLine, trainers));
        }