Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace PlantDiscovery_Krassy
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- // Dictionary with names and rarities
- var plantsRarity = new Dictionary<string, int>();
- var ratings = new Dictionary<string, List<double>>();
- for (int i = 0; i < n; i++)
- {
- var info = Console.ReadLine().Split("<->", StringSplitOptions.RemoveEmptyEntries).ToArray();
- var namePlant = info[0];
- var rarity = int.Parse(info[1]);
- if (!plantsRarity.ContainsKey(namePlant))
- {
- plantsRarity.Add(namePlant, rarity);
- ratings.Add(namePlant, new List<double>());
- }
- else
- {
- plantsRarity[namePlant] = rarity;
- ratings[namePlant] = new List<double>();
- }
- }
- var input = Console.ReadLine();
- while (input != "Exhibition")
- {
- var data = input.Split(':', StringSplitOptions.RemoveEmptyEntries).ToArray();
- var command = data[0];
- var extraInfo = data[1].Split("-", StringSplitOptions.RemoveEmptyEntries).ToArray();
- var nameP = extraInfo[0];
- var ratingOrRarity = extraInfo[1];
- if (command == "Rate")
- {
- ratings[nameP] = new List<double>();
- ratings[nameP].Add(double.Parse(ratingOrRarity));
- }
- else if (command == "Update")
- {
- plantsRarity[nameP] = int.Parse(ratingOrRarity);
- }
- else if (command == "Reset")
- {
- ratings[nameP].Clear();
- ratings[nameP].Add(0);
- }
- else
- {
- Console.WriteLine("Error");
- break;
- }
- input = Console.ReadLine();
- }
- if (input == "Exhibition")
- {
- Console.WriteLine("Plants for the exhibition:");
- // Problem!!!!!!
- var raritySorted = plantsRarity.OrderByDescending(x => x.Value).ToDictionary(a => a.Key, b => b.Value);
- foreach (var (plant, rarity) in raritySorted)
- {
- if (ratings.ContainsKey(plant))
- {
- double average = 0;
- if (ratings[plant].Any())
- {
- average = ratings[plant].Average();
- }
- ratings[plant].Clear();
- ratings[plant].Add(average);
- }
- }
- //foreach (var (plant, info) in ratings.OrderByDescending(a => a.Value[0]).ThenByDescending(b => b.Value[1]))
- //{
- // Console.WriteLine($"- {plant}; Rarity: {info[0]}; Rating: {info[1]:f2}");
- //}
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement