Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- namespace NewChatGPT
- {
- internal class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, Pokemon> pokemonByName = new Dictionary<string, Pokemon>();
- Dictionary<string, List<Pokemon>> pokemonByType = new Dictionary<string, List<Pokemon>>();
- List<Pokemon> pokemonList = new List<Pokemon>();
- StringBuilder output = new StringBuilder();
- string input;
- while ((input = Console.ReadLine()) != "end")
- {
- var parameters = input.Split(' ');
- string command = parameters[0];
- if (command == "add")
- {
- string name = parameters[1];
- string type = parameters[2];
- int power = int.Parse(parameters[3]);
- int position = int.Parse(parameters[4]);
- Pokemon newPokemon = new Pokemon(name, type, power);
- if (position > pokemonList.Count)
- {
- pokemonList.Add(newPokemon);
- }
- else
- {
- pokemonList.Insert(position - 1, newPokemon);
- }
- pokemonByName[name] = newPokemon;
- if (!pokemonByType.ContainsKey(type))
- {
- pokemonByType[type] = new List<Pokemon>();
- }
- pokemonByType[type].Add(newPokemon);
- output.AppendLine($"Added pokemon {name} to position {position}");
- }
- else if (command == "find")
- {
- string type = parameters[1];
- if (pokemonByType.ContainsKey(type))
- {
- var findPokemon = pokemonByType[type]
- .OrderBy(x => x.Name)
- .ThenByDescending(x => x.Power)
- .Take(5)
- .Select(x => $"{x.Name}({x.Power})");
- output.AppendLine($"Type {type}: {string.Join("; ", findPokemon)}");
- }
- else
- {
- output.AppendLine($"Type {type}: ");
- }
- }
- else if (command == "ranklist")
- {
- int start = int.Parse(parameters[1]) - 1;
- int end = int.Parse(parameters[2]) - 1;
- var findRankOfPokemons = pokemonList
- .GetRange(start, end - start + 1)
- .Select((pokemons, index) => $"{start + index + 1}. {pokemons.Name}({pokemons.Power})");
- output.AppendLine(string.Join("; ", findRankOfPokemons));
- }
- }
- Console.WriteLine(output);
- }
- public struct Pokemon
- {
- public Pokemon(string name, string type, int power)
- {
- this.Name = name;
- this.Type = type;
- this.Power = power;
- }
- public string Name { get; set; }
- public string Type { get; set; }
- public int Power { get; set; }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement