Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- namespace Plant_Discovery
- {
- class Program
- {
- static void Main(string[] args)
- {
- int countOfLine = int.Parse(Console.ReadLine());
- Dictionary<string, int> plantRarity = new Dictionary<string, int>();
- Dictionary<string, List<double>> plantRate = new Dictionary<string, List<double>>();
- for (int i = 0; i < countOfLine; i++)
- {
- string line = Console.ReadLine();
- string[] lineSplit = line.Split("<->").ToArray();
- string name = lineSplit[0];
- int rarity = int.Parse(lineSplit[1]);
- if (!plantRarity.ContainsKey(name))
- {
- plantRarity.Add(name, rarity);
- plantRate.Add(name, new List<double>());
- }
- else
- {
- plantRarity[name] = rarity;
- }
- }
- while (true)
- {
- string line = Console.ReadLine();
- if (line == "Exhibition")
- {
- Console.WriteLine("Plants for the exhibition:");
- var sortedPlants = plantRarity
- .OrderByDescending(p => p.Value)
- .ThenByDescending(p => plantRate[p.Key].Count > 0
- ? plantRate[p.Key].Average()
- : 0.0);
- foreach (var (plantName, rarity) in sortedPlants)
- {
- double rating = plantRate[plantName].Count > 0
- ? plantRate[plantName].Average()
- : 0.0;
- Console.WriteLine(
- $"- {plantName}; Rarity: {rarity}; Rating: {rating:F2}");
- }
- return;
- }
- string[] lineSplit = Regex.Split(line, @"[:-]")
- .Select(s => s.Trim())
- .ToArray();
- string name = lineSplit[1];
- if (!plantRarity.ContainsKey(name))
- {
- Console.WriteLine("error");
- continue;
- }
- switch (lineSplit[0])
- {
- case "Rate":
- double rate = double.Parse(lineSplit[2]);
- plantRate[name].Add(rate);
- break;
- case "Update":
- int newRarity = int.Parse(lineSplit[2]);
- plantRarity[name] = newRarity;
- break;
- case "Reset":
- plantRate[name].Clear();
- break;
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement