Advertisement
Guest User

Plant_Discovery

a guest
Aug 30th, 2020
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.31 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Plant_Discovery
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int numberOfPlants = int.Parse(Console.ReadLine());
  12. Dictionary<string, int> rarities = new Dictionary<string, int>();
  13. Dictionary<string, List<double>> ratings = new Dictionary<string, List<double>>();
  14.  
  15. for (int i = 0; i < numberOfPlants; i++)
  16. {
  17. string[] informtionForPlants = Console.ReadLine().Split("<->");
  18. string plant = informtionForPlants[0];
  19. int rarity = int.Parse(informtionForPlants[1]);
  20.  
  21. rarities.Add(plant, rarity);
  22. ratings.Add(plant, new List<double>());
  23. }
  24.  
  25. string command;
  26.  
  27. while ((command = Console.ReadLine()) != "Exhibition")
  28. {
  29. string[] receivedCommand = command.Split(": ");
  30. string firstPartOfCommand = receivedCommand[0];
  31. string[] secondPartOfCommand = receivedCommand[1].Split(" - ");
  32. string plant = secondPartOfCommand[0];
  33.  
  34. if (firstPartOfCommand == "Rate")
  35. {
  36. int rating = int.Parse(secondPartOfCommand[1]);
  37.  
  38. ratings[plant].Add(rating);
  39. }
  40.  
  41. else if (firstPartOfCommand == "Update")
  42. {
  43. int rarity = int.Parse(secondPartOfCommand[1]);
  44.  
  45. rarities[plant] = rarity;
  46. }
  47.  
  48. else if (firstPartOfCommand == "Reset")
  49. {
  50. ratings[plant].RemoveAll(x => x > 0);
  51. }
  52.  
  53. else
  54. {
  55. Console.WriteLine("error");
  56. }
  57. }
  58.  
  59. Console.WriteLine("Plants for the exhibition:");
  60.  
  61. foreach (var kvp in rarities.OrderByDescending(x => x.Value).ThenByDescending(x => x.Key))
  62. {
  63. Console.Write($"- {kvp.Key}; Rarity: {kvp.Value}; ");
  64.  
  65. /*foreach (var item in ratings.OrderByDescending(x => x.Value.Sum() / x.Value.Count))
  66. {
  67.  
  68. }*/
  69. }
  70. }
  71. }
  72. }
  73.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement