Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- namespace ConsoleApplication.Random
- {
- class Region
- {
- public Region()
- {
- this.Roses = new List<Rose>();
- }
- public string Name { get; set; }
- public ICollection<Rose> Roses{ get; set; }
- public int TotalAmountOfRoses { get; set; }
- }
- class Rose
- {
- public string ColorName { get; set; }
- public int Amount { get; set; }
- }
- class Program
- {
- static void Main(string[] args)
- {
- string input;
- var regions = new List<Region>();
- while((input = Console.ReadLine()) != "Icarus, Ignite!")
- {
- var info = input.Split(new string[] {" "}, StringSplitOptions.RemoveEmptyEntries);
- var regionName = info[1].Substring(1, info.Length - 2);
- var roseColor = info[2].Substring(1, info.Length - 2);
- var roseCount = int.Parse(info[3]);
- var regionFromList = regions.FirstOrDefault(r => r.Name == regionName);
- if(regionFromList != null)
- {
- var roseFromRegion = regionFromList.Roses.FirstOrDefault(ro => ro.ColorName == roseColor);
- if(roseFromRegion != null)
- {
- roseFromRegion.Amount += roseCount;
- }
- else
- {
- regionFromList.Roses.Add(new Rose { ColorName = roseColor, Amount = roseCount });
- }
- }
- else
- {
- regions.Add(new Region { Name = regionName, Roses = new List<Rose>() { new Rose {ColorName = roseColor, Amount=roseCount } } });
- }
- }
- foreach (var region in regions)
- {
- var totalAmount = 0;
- foreach (var rose in region.Roses)
- {
- totalAmount += rose.Amount;
- }
- region.TotalAmountOfRoses = totalAmount;
- }
- regions = regions.OrderByDescending(x => x.TotalAmountOfRoses).ThenBy(y => y.Name).ToList();
- foreach (var region in regions)
- {
- region.Roses = region.Roses.OrderBy(x => x.Amount).ThenBy(y => y.ColorName).ToList();
- Console.WriteLine(region.Name);
- foreach (var rose in region.Roses)
- {
- Console.WriteLine($"*--{rose.ColorName} | {rose.Amount}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement