Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03.Plant_Factory
- {
- class Program
- {
- static void Main(string[] args)
- {
- int n = int.Parse(Console.ReadLine());
- var plants = new Dictionary<string, Dictionary<string, double>>();
- for (int i = 0; i < n; i++)
- {
- string[] input = Console.ReadLine().Split("<->");
- string plant = input[0];
- int rarity = int.Parse(input[1]);
- if (!plants.ContainsKey(plant))
- {
- plants.Add(plant, new Dictionary<string, double>
- {
- {"rarity", rarity },
- {"rating", 0 }
- });
- }
- else
- {
- plants[plant]["rarity"] += rarity;
- }
- }
- string commands = String.Empty;
- while ((commands = Console.ReadLine()) != "Exhibition")
- {
- string[] tokens = commands.Split(": ");
- string command = tokens[0];
- if (command.Contains("Rate"))
- {
- string[] elements = tokens[1].Split(" - ");
- string plant = elements[0];
- double rating = double.Parse(elements[1]);
- if (!plants.ContainsKey(plant))
- {
- plants.Add(plant, new Dictionary<string, double>
- {
- {"rarity", 0 },
- {"rating", rating }
- });
- }
- else
- {
- plants[plant]["rating"] += rating;
- }
- }
- else if (command.Contains("Update"))
- {
- string[] elements = tokens[1].Split(" - ");
- string plant = elements[0];
- double rarity = double.Parse(elements[1]);
- if (!plants.ContainsKey(plant))
- {
- plants.Add(plant, new Dictionary<string, double>
- {
- {"rarity", rarity },
- {"rating", 0 }
- });
- }
- else
- {
- plants[plant]["rarity"] = rarity;
- }
- }
- else if (command.Contains("Reset"))
- {
- string plant = tokens[1];
- if (plants.ContainsKey(plant))
- {
- plants[plant]["rating"] = 0.00;
- }
- }
- else
- {
- Console.WriteLine("error");
- }
- }
- Console.WriteLine($"Plants for the exhibition:");
- foreach (var plant in plants.OrderByDescending(x => x.Value["rarity"]).ThenByDescending(x => x.Value["rating"]).ToDictionary(x => x.Key, x => x.Value))
- {
- Console.WriteLine($"- {plant.Key}; Rarity: {plant.Value["rarity"]}; Rating: {plant.Value["rating"]:f2}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement