Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Problem04
- {
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text.RegularExpressions;
- public class Program
- {
- public static void Main(string[] args)
- {
- List<Region> regions = new List<Region>();
- while (true)
- {
- var inputLine = Console.ReadLine();
- if (inputLine == "Count em all")
- {
- break;
- }
- var inputArr = Regex.Split(inputLine, " -> ");
- var regionName = inputArr[0].Trim();
- var meteorType = inputArr[1].Trim();
- long countMeteors = long.Parse(inputArr[2]);
- var existRegion = regions.FindIndex(r => r.Name == regionName);
- if (existRegion==-1)
- {
- regions.Add(new Region(regionName));
- var currentRegion = regions.First(r => r.Name == regionName);
- var greenCount = currentRegion.Meteors[0].Count;
- var redCount = currentRegion.Meteors[1].Count;
- var blackCount = currentRegion.Meteors[2].Count;
- switch (meteorType)
- {
- case "Green":
- currentRegion.Meteors[0].Count += countMeteors;
- currentRegion.Calculate();
- break;
- case "Red":
- currentRegion.Meteors[1].Count += countMeteors;
- currentRegion.Calculate();
- break;
- case "Black":
- currentRegion.Meteors[2].Count += countMeteors;
- currentRegion.Calculate();
- break;
- }
- }
- else
- {
- var currentRegion = regions.First(r => r.Name == regionName);
- switch (meteorType)
- {
- case "Green":
- currentRegion.Meteors[0].Count += countMeteors;
- currentRegion.Calculate();
- break;
- case "Red":
- currentRegion.Meteors[1].Count += countMeteors;
- currentRegion.Calculate();
- break;
- case "Black":
- currentRegion.Meteors[2].Count += countMeteors;
- currentRegion.Calculate();
- break;
- }
- }
- }
- var newList =
- regions.OrderByDescending(r => r.Meteors[2].Count).ThenBy(r => r.Name.Length).ThenBy(r => r.Name).ToList();
- foreach (var region in newList)
- {
- var sortedMeteors = region.Meteors.OrderByDescending(m => m.Count).ThenBy(m => m.Name);
- Console.WriteLine(region.Name);
- foreach (var meteor in sortedMeteors)
- {
- Console.WriteLine("-> " +meteor.Name + " : " + meteor.Count);
- }
- }
- }
- }
- public class Meteor
- {
- public string Name { get; set; }
- public long Count { get; set; }
- public Meteor(string name,long count)
- {
- this.Name = name;
- this.Count = count;
- }
- }
- public class Region
- {
- private const int mil = 1000000;
- public string Name { get; set; }
- public Meteor[] Meteors { get; set; }
- public Region(string name)
- {
- this.Name = name;
- this.Meteors=new Meteor[3];
- this.Meteors[0]=new Meteor("Green",0);
- this.Meteors[1] = new Meteor("Red",0);
- this.Meteors[2] = new Meteor("Black",0);
- }
- public void Calculate()
- {
- var greenMeteor = this.Meteors[0];
- var redMeteor = this.Meteors[1];
- var blackMeteor = this.Meteors[2];
- if (greenMeteor.Count >= mil)
- {
- var rest = greenMeteor.Count%mil;
- var combinated = greenMeteor.Count / mil;
- greenMeteor.Count = rest;
- redMeteor.Count += combinated;
- }
- if (redMeteor.Count >= mil)
- {
- var rest = redMeteor.Count % mil;
- var combinated = redMeteor.Count / mil;
- redMeteor.Count = rest;
- blackMeteor.Count += combinated;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement