Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace zadacha
- {
- class Program
- {
- static void Main(string[] args)
- {
- int times = int.Parse(Console.ReadLine());
- Dictionary<string, List<double>> rarity = new Dictionary<string, List<double>>();
- Dictionary<string, List<double>> rating = new Dictionary<string, List<double>>();
- for (int i = 0; i < times; i++)
- {
- string[] input = Console.ReadLine().Split("<->");
- //"{plant}<->{rarity}"
- rarity[input[0]] = new List<double>();
- rarity[input[0]].Add(double.Parse(input[1]));
- rating[input[0]] = new List<double>();
- }
- string[] command = Console.ReadLine().Split(": ");
- while (command[0] != "Exhibition")
- {
- string[] moreCommand = command[1].Split(" - ");
- if (command[0] == "Rate")
- {
- //• Rate: {plant} - {rating}
- if (rating.ContainsKey(moreCommand[0]))
- {
- double number = double.Parse(moreCommand[1]);
- rating[moreCommand[0]].Add(number);
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if (command[0] == "Update")
- {
- //• Update: {plant} - {new_rarity}
- if (rarity.ContainsKey(moreCommand[0]))
- {
- rarity[moreCommand[0]].Clear();
- rarity[moreCommand[0]].Add(double.Parse(moreCommand[1]));
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if (command[0] == "Reset")
- {
- if (rating.ContainsKey(moreCommand[0]))
- {
- rating[moreCommand[0]].Clear();
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else
- {
- Console.WriteLine("error");
- }
- command = Console.ReadLine().Split(": ");
- }
- foreach (var item in rating)
- {
- double average = 0;
- if (item.Value.Count == 0)
- {
- rarity[item.Key].Add(0);
- }
- else
- {
- average = item.Value.Average();
- rarity[item.Key].Add(average);
- }
- }
- Console.WriteLine("Plants for the exhibition:");
- foreach (var item in rarity.OrderByDescending(x=>x.Value[0]).ThenByDescending(x=>x.Value[1]))
- {
- Console.WriteLine($"- {item.Key}; Rarity: {item.Value[0]}; Rating: {item.Value[1]:F2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment