LardaX

Legendary-Farming-80points

Oct 8th, 2016
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 5.50 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 Legendary_Farming
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             Dictionary<string, int> materials = new Dictionary<string, int>();
  14.             string legendarySword = "";
  15.  
  16.             while (true)
  17.             {
  18.                 string[] materialsObtained = Console.ReadLine().ToLower().Split().ToArray();
  19.  
  20.                 bool isEnough = false;
  21.  
  22.                 for (int i = 1; i < materialsObtained.Length; i += 2)
  23.                 {
  24.                     if (!materials.ContainsKey(materialsObtained[i]))
  25.                     {
  26.                         materials.Add(materialsObtained[i], 0);
  27.                     }
  28.  
  29.                     materials[materialsObtained[i]] += int.Parse(materialsObtained[i - 1]);
  30.  
  31.                     if (materials[materialsObtained[i]] >= 250)
  32.                     {
  33.                         foreach (var pair in materials)
  34.                         {
  35.                             if (pair.Value >= 250 && pair.Key.Equals("shards"))
  36.                             {
  37.                                 legendarySword = "Shadowmourne";
  38.                                 isEnough = true;
  39.                             }
  40.                             else if (pair.Value >= 250 && pair.Key.Equals("fragments"))
  41.                             {
  42.                                 legendarySword = "Valanyr";
  43.                                 isEnough = true;
  44.                             }
  45.                             else if (pair.Value >= 250 && pair.Key.Equals("motes"))
  46.                             {
  47.                                 legendarySword = "Dragonwrath";
  48.                                 isEnough = true;
  49.                             }
  50.                         }
  51.                         //   if (materials[materialsObtained[i]].Equals("shards"))
  52.                         //   {
  53.                         //       legendarySword = "Shadowmourne";
  54.                         //       isEnough = true;
  55.                         //       break;
  56.                         //   }
  57.                         //   else if (materials[materialsObtained[i]].Equals("fragments"))
  58.                         //   {
  59.                         //       legendarySword = "Valanyr";
  60.                         //       isEnough = true;
  61.                         //       break;
  62.                         //   }
  63.                         //   else if (materials[materialsObtained[i]].Equals("motes"))
  64.                         //   {
  65.                         //       legendarySword = "Dragonwrath";
  66.                         //       isEnough = true;
  67.                         //       break;
  68.                         //   }
  69.                     }
  70.                     if (isEnough)
  71.                     {
  72.                         break;
  73.                     }
  74.                 }
  75.  
  76.                 if (isEnough)
  77.                 {
  78.                     break;
  79.                 }
  80.             }
  81.  
  82.             PrintWeapon(materials, legendarySword);
  83.  
  84.         }
  85.  
  86.         private static void PrintWeapon(Dictionary<string, int> materials, string legendarySword)
  87.         {
  88.             Console.WriteLine($"{legendarySword} obtained!");
  89.             Dictionary<string, int> legendaryMaterials = new Dictionary<string, int>();
  90.             SortedDictionary<string, int> otherMaterials = new SortedDictionary<string, int>();
  91.  
  92.             FillDictionaries(materials, legendaryMaterials, otherMaterials);
  93.  
  94.             PrintLegendaryMaterials(legendaryMaterials);
  95.             PrintOtherMaterials(otherMaterials);
  96.  
  97.         }
  98.  
  99.         private static void PrintOtherMaterials(SortedDictionary<string, int> otherMaterials)
  100.         {
  101.             foreach (KeyValuePair<string, int> material in otherMaterials)
  102.             {
  103.                 Console.WriteLine($"{material.Key}: {material.Value}");
  104.             }
  105.         }
  106.  
  107.         private static void PrintLegendaryMaterials(Dictionary<string, int> legendaryMaterials)
  108.         {
  109.             foreach (KeyValuePair<string, int> material in legendaryMaterials.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  110.             {
  111.                 Console.WriteLine($"{material.Key}: {material.Value}");
  112.             }
  113.         }
  114.  
  115.         private static void FillDictionaries(Dictionary<string, int> materials, Dictionary<string, int> legendaryMaterials, SortedDictionary<string, int> otherMaterials)
  116.         {
  117.             foreach (KeyValuePair<string, int> material in materials)
  118.             {
  119.                 if (material.Key.Equals("shards") || material.Key.Equals("fragments") || material.Key.Equals("motes"))
  120.                 {
  121.                     legendaryMaterials.Add(material.Key, material.Value);
  122.                     if (material.Value > 250)
  123.                     {
  124.                         legendaryMaterials[material.Key] -= 250;
  125.                     }
  126.                 }
  127.                 else
  128.                 {
  129.                     otherMaterials.Add(material.Key, material.Value);
  130.                 }
  131.             }
  132.             if (!legendaryMaterials.ContainsKey("fragments"))
  133.             {
  134.                 legendaryMaterials.Add("fragments", 0);
  135.             }
  136.             if (!legendaryMaterials.ContainsKey("shards"))
  137.             {
  138.                 legendaryMaterials.Add("shards", 0);
  139.             }
  140.             if (!legendaryMaterials.ContainsKey("motes"))
  141.             {
  142.                 legendaryMaterials.Add("motes", 0);
  143.             }
  144.         }
  145.     }
  146. }
Advertisement
Add Comment
Please, Sign In to add comment