Advertisement
MeliDragon

Untitled

May 4th, 2023
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.44 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace NewChatGPT
  7. {
  8. internal class Program
  9. {
  10. static void Main(string[] args)
  11. {
  12. Dictionary<string, Pokemon> pokemonByName = new Dictionary<string, Pokemon>();
  13. Dictionary<string, List<Pokemon>> pokemonByType = new Dictionary<string, List<Pokemon>>();
  14. List<Pokemon> pokemonList = new List<Pokemon>();
  15. StringBuilder output = new StringBuilder();
  16.  
  17. string input;
  18.  
  19. while ((input = Console.ReadLine()) != "end")
  20. {
  21. var parameters = input.Split(' ');
  22.  
  23. string command = parameters[0];
  24.  
  25. if (command == "add")
  26. {
  27. string name = parameters[1];
  28. string type = parameters[2];
  29. int power = int.Parse(parameters[3]);
  30. int position = int.Parse(parameters[4]);
  31.  
  32. Pokemon newPokemon = new Pokemon(name, type, power);
  33.  
  34. if (position > pokemonList.Count)
  35. {
  36. pokemonList.Add(newPokemon);
  37. }
  38. else
  39. {
  40. pokemonList.Insert(position - 1, newPokemon);
  41. }
  42.  
  43. pokemonByName[name] = newPokemon;
  44.  
  45. if (!pokemonByType.ContainsKey(type))
  46. {
  47. pokemonByType[type] = new List<Pokemon>();
  48. }
  49. pokemonByType[type].Add(newPokemon);
  50.  
  51. output.AppendLine($"Added pokemon {name} to position {position}");
  52. }
  53. else if (command == "find")
  54. {
  55. string type = parameters[1];
  56.  
  57. if (pokemonByType.ContainsKey(type))
  58. {
  59. var findPokemon = pokemonByType[type]
  60. .OrderBy(x => x.Name)
  61. .ThenByDescending(x => x.Power)
  62. .Take(5)
  63. .Select(x => $"{x.Name}({x.Power})");
  64.  
  65. output.AppendLine($"Type {type}: {string.Join("; ", findPokemon)}");
  66. }
  67. else
  68. {
  69. output.AppendLine($"Type {type}: ");
  70. }
  71. }
  72. else if (command == "ranklist")
  73. {
  74. int start = int.Parse(parameters[1]) - 1;
  75. int end = int.Parse(parameters[2]) - 1;
  76. var findRankOfPokemons = pokemonList
  77. .GetRange(start, end - start + 1)
  78. .Select((pokemons, index) => $"{start + index + 1}. {pokemons.Name}({pokemons.Power})");
  79.  
  80. output.AppendLine(string.Join("; ", findRankOfPokemons));
  81. }
  82. }
  83.  
  84. Console.WriteLine(output);
  85. }
  86. public struct Pokemon
  87. {
  88. public Pokemon(string name, string type, int power)
  89. {
  90. this.Name = name;
  91. this.Type = type;
  92. this.Power = power;
  93. }
  94.  
  95. public string Name { get; set; }
  96. public string Type { get; set; }
  97. public int Power { get; set; }
  98. }
  99. }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement