emilia98

Cubic Assault

Feb 6th, 2018
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.60 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _04.CubicAssault
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string input = Console.ReadLine();
  14.             var assaultData = new Dictionary<string, Dictionary<string, long>>();
  15.  
  16.             while (input != "Count em all")
  17.             {
  18.                 var splitInput = input.Split(new string[] { " -> " },
  19.                                              StringSplitOptions.RemoveEmptyEntries)
  20.                                       .ToArray();
  21.  
  22.                 string regionName = splitInput[0];
  23.                 string meteorType = splitInput[1];
  24.                 int count = int.Parse(splitInput[2]);
  25.  
  26.                 if (!assaultData.ContainsKey(regionName))
  27.                 {
  28.                     assaultData.Add(regionName, new Dictionary<string, long>());
  29.                     assaultData[regionName].Add("Black", 0);
  30.                     assaultData[regionName].Add("Red", 0);
  31.                     assaultData[regionName].Add("Green", 0);
  32.                 }
  33.                 if (assaultData[regionName].ContainsKey(meteorType))
  34.                 {
  35.                     assaultData[regionName][meteorType] += count;
  36.  
  37.                     long green = assaultData[regionName]["Green"];
  38.                     long convertToRed = green / 1000000;
  39.  
  40.                     assaultData[regionName]["Red"] += convertToRed;
  41.                     assaultData[regionName]["Green"] -= (convertToRed * 1000000);
  42.                     long red = assaultData[regionName]["Red"];
  43.                     long convertToBlack = red / 1000000;
  44.  
  45.  
  46.                     assaultData[regionName]["Black"] += convertToBlack;
  47.                     assaultData[regionName]["Red"] -= (convertToBlack * 1000000);
  48.                 }
  49.                 input = Console.ReadLine();
  50.  
  51.             }
  52.        
  53.             foreach (var pair in assaultData.OrderByDescending(x => x.Value["Black"])
  54.                                             .ThenBy(y => y.Key.Length)
  55.                                             .ThenBy(z => z.Key))
  56.             {
  57.                 string meteor = pair.Key;
  58.                 var meteorsData = pair.Value;
  59.                 Console.WriteLine(meteor);
  60.  
  61.                 foreach (var meteors in meteorsData.OrderByDescending(x => x.Value)
  62.                                                    .ThenBy(x => x.Key))
  63.                 {
  64.                     Console.WriteLine("-> {0} : {1}", meteors.Key, meteors.Value);
  65.                 }
  66.             }
  67.         }
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment