Advertisement
Guest User

Untitled

a guest
Jun 11th, 2018
321
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.68 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _09.Legendary_Farming
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             const int neededQuantity = 250;
  12.  
  13.             var keyMaterials = new Dictionary<string, int>()
  14.             {
  15.                 {"shards", 0},
  16.                 {"fragments", 0},
  17.                 {"motes", 0}
  18.             };
  19.  
  20.             var junkMaterials = new SortedDictionary<string, int>();
  21.  
  22.             while (true)
  23.             {
  24.                 var batch = Console.ReadLine()
  25.                     .Split()
  26.                     .ToArray();
  27.  
  28.                 var length = batch.Length;
  29.  
  30.                 for (int i = 0; i < length; i += 2)
  31.                 {
  32.                     var quantity = int.Parse(batch[i]);
  33.                     var material = batch[i + 1].ToLower();
  34.  
  35.                     if (keyMaterials.ContainsKey(material))
  36.                     {
  37.                         keyMaterials[material] += quantity;
  38.  
  39.                         if (keyMaterials[material] >= neededQuantity)
  40.                         {
  41.                             PrintResult(neededQuantity, keyMaterials,
  42.                                 junkMaterials, material);
  43.                             return;
  44.                         }
  45.  
  46.                         continue;
  47.                     }
  48.  
  49.                     if (!junkMaterials.ContainsKey(material))
  50.                     {
  51.                         junkMaterials[material] = 0;
  52.                     }
  53.  
  54.                     junkMaterials[material] += quantity;
  55.                 }
  56.             }
  57.         }
  58.  
  59.         private static void PrintResult(int neededQuantity,
  60.             Dictionary<string, int> keyMaterials,
  61.             SortedDictionary<string, int> junkMaterials,
  62.             string material)
  63.         {
  64.             var item = String.Empty;
  65.             switch (material)
  66.             {
  67.                 case "shards":
  68.                     item = "Shadowmourne";
  69.                     break;
  70.                 case "fragments":
  71.                     item = "Valanyr";
  72.                     break;
  73.                 case "motes":
  74.                     item = "Dragonwrath";
  75.                     break;
  76.             }
  77.             Console.WriteLine($"{item} obtained!");
  78.  
  79.             keyMaterials[material] -= neededQuantity;
  80.  
  81.             var result = keyMaterials
  82.                 .OrderByDescending(x => x.Value)
  83.                 .ThenBy(x => x.Key)
  84.                 .Concat(junkMaterials)
  85.                 .ToArray();
  86.  
  87.             foreach (var pair in result)
  88.             {
  89.                 Console.WriteLine($"{pair.Key}: {pair.Value}");
  90.             }
  91.         }
  92.     }
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement