Advertisement
Guest User

09. Legendary Farming

a guest
Feb 19th, 2018
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. namespace _09._Legendary_Farming
  2. {
  3.     using System;
  4.     using System.Collections.Generic;
  5.     using System.Linq;
  6.  
  7.     public class LegendaryFarming
  8.     {
  9.         public static void Main()
  10.         {
  11.             SortedDictionary<string, int> data = new SortedDictionary<string, int>();
  12.             Dictionary<string, int> keyMaterialsData = new Dictionary<string, int>()
  13.             {
  14.                 {"shards", 0}, {"fragments", 0}, {"motes", 0}
  15.             };
  16.             string[] legendaryItems = new string[] { "Shadowmourne", "Valanyr", "Dragonwrath" };
  17.             string keyMaterial = string.Empty;
  18.             bool isObtained = true;
  19.  
  20.             while (isObtained)
  21.             {
  22.                 var inputLine = Console.ReadLine().ToLower().Split();
  23.  
  24.                 for (int i = 0; i < inputLine.Length; i += 2)
  25.                 {
  26.                     int quantity = int.Parse(inputLine[i]);
  27.                     string material = inputLine[i + 1];
  28.  
  29.                     if (material == "shards" || material == "fragments" || material == "motes")
  30.                     {
  31.                         keyMaterialsData[material] += quantity;
  32.                     }
  33.                     else
  34.                     {
  35.                         if (!data.ContainsKey(material))
  36.                         {
  37.                             data[material] = quantity;
  38.                         }
  39.                         else
  40.                         {
  41.                             data[material] += quantity;
  42.                         }
  43.                     }
  44.  
  45.                     if (keyMaterialsData.ContainsKey(material) && keyMaterialsData[material] >= 250)
  46.                     {
  47.                         keyMaterialsData[material] -= 250;
  48.                         keyMaterial = material;
  49.                         isObtained = false;
  50.                         break;
  51.                     }
  52.                 }
  53.  
  54.             }
  55.  
  56.             switch (keyMaterial)
  57.             {
  58.                 case "fragments":
  59.                     Console.WriteLine("Valanyr obtained!");
  60.                     break;
  61.                 case "shards":
  62.                     Console.WriteLine("Shadowmourne obtained!");
  63.                     break;
  64.                 case "motes":
  65.                     Console.WriteLine("Dragonwrath obtained!");
  66.                     break;
  67.             }
  68.  
  69.             foreach (var kvp in keyMaterialsData.OrderByDescending(v => v.Value).ThenBy(k => k.Key))
  70.             {
  71.                 Console.WriteLine($"{kvp.Key}: {kvp.Value}");
  72.             }
  73.  
  74.             foreach (var kvp in data)
  75.             {
  76.                 Console.WriteLine($"{kvp.Key}: {kvp.Value}");
  77.             }
  78.  
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement