Advertisement
amphibia89

Legendary Farming

May 26th, 2016
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.36 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5.  
  6. class Program
  7. {
  8.     private const int QuantityForLegendaryItem = 250;
  9.     private static readonly Dictionary<string, string> MaterialLegendaryItemTable =
  10.         new Dictionary<string, string>
  11.         {
  12.             { "shards", "Shadowmourne"},
  13.             { "fragments", "Valanyr"},
  14.             { "motes", "Dragonwrath"}
  15.         };
  16.  
  17.     public static void Main()
  18.     {
  19. #if DEBUG
  20.         Console.SetIn(new StreamReader("../../input.txt"));
  21. #endif
  22.         string legendaryItem = null;
  23.         var junkMaterialQuantityPair = new SortedDictionary<string, int>();
  24.         var keyMaterialQuantityPair = new SortedDictionary<string, int>()
  25.         {
  26.             { "shards", 0 }, { "fragments", 0 }, { "motes", 0 }
  27.         };
  28.  
  29.         string input = Console.ReadLine();
  30.         while (!string.IsNullOrEmpty(input))
  31.         {
  32.             string[] material = input.Split()
  33.                 .Where((element, index) => index % 2 != 0)
  34.                 .Select(element => element.ToLower())
  35.                 .ToArray();
  36.  
  37.             int[] quantity = input.Split()
  38.                 .Where((element, index) => index % 2 == 0)
  39.                 .Select(int.Parse)
  40.                 .ToArray();
  41.  
  42.             legendaryItem =
  43.                 UpdateMaterialQuantities(keyMaterialQuantityPair, junkMaterialQuantityPair,
  44.                     material, quantity);
  45.             if (legendaryItem != null)
  46.                 break;
  47.  
  48.             input = Console.ReadLine();
  49.         }
  50.  
  51.         DisplayOutput(keyMaterialQuantityPair, junkMaterialQuantityPair, legendaryItem);
  52.     }
  53.  
  54.     private static void DisplayOutput(SortedDictionary<string, int> keyMaterialQuantityPair, SortedDictionary<string, int> junkMaterialQuantityPair, string legendaryItem)
  55.     {
  56.         Console.WriteLine($"{legendaryItem} obtained!");
  57.         Console.WriteLine(string.Join("\n", keyMaterialQuantityPair
  58.             .OrderByDescending(pair => pair.Value)
  59.             //.ThenBy(pair => pair.Key)
  60.             .Select(pair => $"{pair.Key}: {pair.Value}")
  61.             .ToArray()));
  62.         Console.WriteLine(string.Join("\n", junkMaterialQuantityPair
  63.             .Select(pair => $"{pair.Key}: {pair.Value}")
  64.             .ToArray()));
  65.     }
  66.  
  67.     private static string UpdateMaterialQuantities(SortedDictionary<string, int> keyMaterialQuantityPair, SortedDictionary<string, int> junkMaterialQuantityPair, string[] material, int[] quantity)
  68.     {
  69.         for (int index = 0; index < material.Length; index++)
  70.         {
  71.             if (keyMaterialQuantityPair.ContainsKey(material[index]))
  72.             {
  73.                 keyMaterialQuantityPair[material[index]] += quantity[index];
  74.                 if (keyMaterialQuantityPair[material[index]] >= QuantityForLegendaryItem)
  75.                 {
  76.                     keyMaterialQuantityPair[material[index]] -= QuantityForLegendaryItem;
  77.                     return MaterialLegendaryItemTable[material[index]];
  78.                 }
  79.             }
  80.             else
  81.             {
  82.                 junkMaterialQuantityPair[material[index]] =
  83.                     (junkMaterialQuantityPair.ContainsKey(material[index]))
  84.                         ? quantity[index] + junkMaterialQuantityPair[material[index]]
  85.                         : quantity[index];
  86.             }
  87.         }
  88.  
  89.         return null;
  90.     }
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement