Guest User

Untitled

a guest
Aug 9th, 2020
43
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace Problem_3
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int n = int.Parse(Console.ReadLine());
  14.  
  15. Dictionary<string, List<double>> plants = new Dictionary<string, List<double>>();
  16.  
  17. // 0 - rarity;
  18. // from 1 - ratings;
  19.  
  20. for (int i = 0; i < n; i++)
  21. {
  22. string input = Console.ReadLine();
  23.  
  24. string[] splitted = input.Split("<->");
  25.  
  26. string plant = splitted[0];
  27.  
  28. int rarity = int.Parse(splitted[1]);
  29.  
  30. if (!plants.ContainsKey(plant))
  31. {
  32. plants.Add(plant, new List<double> { rarity });
  33. }
  34. else
  35. {
  36. plants[plant][0] = rarity;
  37. }
  38. }
  39.  
  40. string command = Console.ReadLine();
  41.  
  42. while (command != "Exhibition")
  43. {
  44. string[] splitted = command.Split(": ");
  45.  
  46. if (command.Contains("Rate"))
  47. {
  48. string flowerAndRating = splitted[1];
  49.  
  50. string[] flowerStats = flowerAndRating.Split(" - ");
  51.  
  52. string plant = flowerStats[0];
  53.  
  54. int rating = int.Parse(flowerStats[1]);
  55.  
  56. plants[plant].Add(rating);
  57. }
  58. else if (command.Contains("Update"))
  59. {
  60. string flowerAndRarity = splitted[1];
  61.  
  62. string[] splitted2 = flowerAndRarity.Split(" - ");
  63.  
  64. string plant = splitted2[0];
  65.  
  66. int rarity = int.Parse(splitted2[1]);
  67.  
  68. plants[plant][0] = rarity;
  69.  
  70. }
  71. else if (command.Contains("Reset"))
  72. {
  73. string plant = splitted[1];
  74.  
  75. plants[plant].RemoveRange(1, plants[plant].Count - 1);
  76. }
  77. else
  78. {
  79. Console.WriteLine("Error");
  80. }
  81.  
  82. command = Console.ReadLine();
  83. }
  84.  
  85. foreach (var plant in plants)
  86. {
  87.  
  88. double rarity = plant.Value[0];
  89.  
  90. plant.Value.RemoveAt(0);
  91.  
  92. int count = plant.Value.Count;
  93.  
  94. double sum = plant.Value.Sum();
  95.  
  96. if (sum > 0)
  97. {
  98. sum /= count;
  99. }
  100. plant.Value.Clear();
  101. plant.Value.Add(rarity);
  102. plant.Value.Add(sum);
  103.  
  104. }
  105. Console.WriteLine("Plants for the exhibition:");
  106. foreach (var item in plants.OrderByDescending(x => x.Value[0]).ThenByDescending(x => x.Value[1]).ToDictionary(x => x.Key, x => x.Value))
  107. {
  108. Console.WriteLine($"- {item.Key}; Rarity: {(int)item.Value[0]}; Rating: {item.Value[1]:f2}");
  109. }
  110.  
  111.  
  112. }
  113. }
  114. }
  115.  
RAW Paste Data