Advertisement
Guest User

Untitled

a guest
Aug 9th, 2021
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace PlantDiscovery
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. int n = int.Parse(Console.ReadLine());
  12.  
  13. Dictionary<string, int> exhibition = new Dictionary<string, int>();
  14. Dictionary<string, List<double>> rating = new Dictionary<string, List<double>>();
  15.  
  16. for (int i = 0; i < n; i++)
  17. {
  18. string[] input = Console.ReadLine().Split("<->");
  19.  
  20. if (!exhibition.ContainsKey(input[0]))
  21. {
  22. exhibition.Add(input[0], int.Parse(input[1]));
  23. }
  24. else
  25. {
  26. exhibition.Remove(input[0]);
  27. exhibition.Add(input[0], int.Parse(input[1]));
  28. }
  29. }
  30.  
  31. string[] command = Console.ReadLine().Split(new char[] { '-', ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  32.  
  33. while (command[0] != "Exhibition")
  34. {
  35.  
  36. if (command[0] == "Rate")
  37. {
  38. if (exhibition.ContainsKey(command[1]))
  39. {
  40. if (!rating.ContainsKey(command[1]))
  41. {
  42. rating.Add(command[1], new List<double>());
  43. }
  44. rating[command[1]].Add(double.Parse(command[2]));
  45. }
  46. else
  47. {
  48. Console.WriteLine("error");
  49. }
  50. }
  51. else if (command[0] == "Update")
  52. {
  53. if (exhibition.ContainsKey(command[1]))
  54. {
  55. exhibition.Remove(command[1]);
  56. exhibition.Add(command[1], int.Parse(command[2]));
  57. }
  58.  
  59. }
  60. else if (command[0] == "Reset")
  61. {
  62. if (rating.ContainsKey(command[1]))
  63. {
  64. rating.Remove(command[1]);
  65. rating.Add(command[1], new List<double> { 0 });
  66. }
  67. else
  68. {
  69. Console.WriteLine("error");
  70. }
  71. }
  72. else
  73. {
  74. Console.WriteLine("error");
  75. }
  76.  
  77. command = Console.ReadLine().Split(new char[] { '-', ':', ' ' }, StringSplitOptions.RemoveEmptyEntries);
  78. }
  79.  
  80. Dictionary<string, List<double>> union = new Dictionary<string, List<double>>();
  81.  
  82. foreach (var item in exhibition)
  83. {
  84. string key = item.Key;
  85. int rarity = item.Value;
  86.  
  87. union.Add(key, new List<double>());
  88. union[key].Add(rarity);
  89. union[key].Add(rating[key].Average());
  90. }
  91.  
  92. Console.WriteLine("Plants for the exhibition:");
  93. foreach (var item in union.OrderByDescending(x => x.Value[0]).ThenByDescending(x => x.Value[1]))
  94. {
  95. Console.WriteLine($" - {item.Key}; Rarity: {item.Value[0]}; Rating: {item.Value[1]:f2}");
  96. }
  97. }
  98. }
  99. }
  100.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement