Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- namespace _03._Plant_Discovery
- {
- class Plant
- {
- public int Rarity { get; set; }
- public List<int> Rating { get; set; }
- public Plant(int rar, List<int> arr)
- {
- Rarity = rar;
- Rating = arr;
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var plants = new Dictionary<string, Plant>();
- for (int i = 1; i <= n; i++)
- {
- string plantInput = Console.ReadLine();
- string name = plantInput.Split("<->")[0];
- int rarity = int.Parse(plantInput.Split("<->")[1]);
- if(plants.ContainsKey(name))
- {
- plants[name].Rarity = rarity;
- }
- else
- {
- Plant plant = new Plant(rarity, new List<int>());
- plants.Add(name, plant);
- }
- }
- string input = string.Empty;
- while ((input = Console.ReadLine()) != "Exhibition")
- {
- if(input.Contains("Rate"))
- {
- string name = input.Split()[1];
- int grade = int.Parse(input.Split()[3]);
- if(plants.ContainsKey(name))
- {
- plants[name].Rating.Add(grade);
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if(input.Contains("Update"))
- {
- string name = input.Split()[1];
- int rar = int.Parse(input.Split()[3]);
- if(plants.ContainsKey(name))
- {
- plants[name].Rarity = rar;
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else if (input.Contains("Reset"))
- {
- string name = input.Split()[1];
- if (plants.ContainsKey(name))
- {
- plants[name].Rating.Clear();
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- foreach (var item in plants)
- {
- if(item.Value.Rating.Count == 0)
- {
- plants[item.Key].Rating.Add(0);
- }
- }
- plants = plants.OrderByDescending(x => x.Value.Rarity).ThenByDescending(x => x.Value.Rating.Average()).ToDictionary(a => a.Key, b => b.Value);
- Console.WriteLine("Plants for the exhibition:");
- foreach (var item in plants)
- {
- if(item.Value.Rating.Count == 0)
- {
- Console.WriteLine($"- {item.Key}; Rarity: {item.Value.Rarity}; Rating: 0.00");
- continue;
- }
- Console.WriteLine($"- {item.Key}; Rarity: {item.Value.Rarity}; Rating: {item.Value.Rating.Average() :f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement