Advertisement
Guest User

09.LegendaryFarming

a guest
Oct 15th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.99 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 _09.LegendaryFarming
  8. {
  9.     class LegendaryFarming
  10.     {
  11.         static void Main()
  12.         {
  13.             Dictionary<string, int> legendaryData = new Dictionary<string, int>();
  14.             SortedDictionary<string, int> junkData = new SortedDictionary<string, int>();
  15.  
  16.             int shardsCntr = 0;
  17.             int fragmentsCntr = 0;
  18.             int motesCntr = 0;
  19.  
  20.             while (shardsCntr < 250 && fragmentsCntr < 250 && motesCntr < 250)
  21.             {
  22.                 string[] tokens = Console.ReadLine().ToLower().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  23.  
  24.                 for (int i = 1; i < tokens.Length; i++)
  25.                 {
  26.                     if (tokens[i] == "shards")
  27.                     {
  28.                         shardsCntr += int.Parse(tokens[i - 1]);
  29.  
  30.                         if (shardsCntr >= 250)
  31.                         {
  32.                             Console.WriteLine($"Shadowmourne obtained!");
  33.                             break;
  34.                         }
  35.                     }
  36.                     else if (tokens[i] == "fragments")
  37.                     {
  38.                         fragmentsCntr += int.Parse(tokens[i - 1]);
  39.  
  40.                         if (fragmentsCntr >= 250)
  41.                         {
  42.                             Console.WriteLine($"Valanyr obtained!");
  43.                             break;
  44.                         }
  45.                     }
  46.                     else if (tokens[i] == "motes")
  47.                     {
  48.                         motesCntr += int.Parse(tokens[i - 1]);
  49.  
  50.                         if (motesCntr >= 250)
  51.                         {
  52.                             Console.WriteLine($"Dragonwrath obtained!");
  53.                             break;
  54.                         }
  55.                     }
  56.                     else
  57.                     {
  58.                         bool isQuantity = CheckIfStringIsNumber(tokens[i]);
  59.  
  60.                         if (!isQuantity)
  61.                         {
  62.                             string material = tokens[i];
  63.                             int quantity = int.Parse(tokens[i - 1]);
  64.  
  65.                             if (!junkData.ContainsKey(material))
  66.                             {
  67.                                 junkData.Add(material, 0);
  68.                             }
  69.                             junkData[material] += quantity;
  70.                         }
  71.                     }
  72.                 }
  73.             }
  74.             AddMaterials(legendaryData, shardsCntr, "shards");
  75.             AddMaterials(legendaryData, fragmentsCntr, "fragments");
  76.             AddMaterials(legendaryData, motesCntr, "motes");
  77.  
  78.             foreach (KeyValuePair<string, int> materials in legendaryData.OrderByDescending(v => v.Value).ThenBy(k => k.Key))
  79.             {
  80.                 string material = materials.Key;
  81.                 int quantity = materials.Value;
  82.  
  83.                 Console.WriteLine($"{material}: {quantity}");
  84.             }
  85.  
  86.             foreach (KeyValuePair<string, int> junk in junkData)
  87.             {
  88.                 string material = junk.Key;
  89.                 int quantity = junk.Value;
  90.  
  91.                 Console.WriteLine($"{material}: {quantity}");
  92.             }
  93.         }
  94.  
  95.         private static bool CheckIfStringIsNumber(string text)
  96.         {
  97.             for (int i = 0; i < text.Length; i++)
  98.             {
  99.                 if (char.IsDigit(text[i]))
  100.                 {
  101.                     return true;
  102.                 }
  103.             }
  104.             return false;
  105.         }
  106.  
  107.         private static void AddMaterials(Dictionary<string, int> data, int materialCntr, string v)
  108.         {
  109.             if (!data.ContainsKey(v))
  110.             {
  111.                 data.Add(v, 0);
  112.             }
  113.  
  114.             if (materialCntr > 250)
  115.             {
  116.                 materialCntr -= 250;
  117.             }
  118.             data[v] = materialCntr;
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement