viktoriq_23

Associative Arrays - Exercise - 03. Legendary Farming

Mar 16th, 2020
597
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5. using System.Text;
  6.  
  7. namespace LegendaryFarming
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             bool itemObtained = false;
  14.             Dictionary<string, int> keymaterials = new Dictionary<string, int>();
  15.             keymaterials.Add("shards", 0);
  16.             keymaterials.Add("fragments", 0);
  17.             keymaterials.Add("motes", 0);
  18.             Dictionary<string, int> junk = new Dictionary<string, int>();
  19.             string obtainedItem = "";
  20.             while (!itemObtained)
  21.             {
  22.                 string[] input = Console.ReadLine().ToLower().Split().ToArray();
  23.                 List<string> materials = new List<string>();
  24.                 List<int> quantities = new List<int>();
  25.                 for (int i = 1; i <= input.Length; i++)//
  26.                 {
  27.                     if (i % 2 != 0)
  28.                         quantities.Add(int.Parse(input[i - 1]));//
  29.                     else
  30.                         materials.Add(input[i - 1]);//
  31.                 }
  32.                 for (int i = 0; i < materials.Count; i++)
  33.                 {
  34.                     if (materials[i] == "shards" || materials[i] == "fragments" || materials[i] == "motes")
  35.                     {
  36.                         if (keymaterials.ContainsKey(materials[i]))
  37.                         {
  38.                             keymaterials[materials[i]] += quantities[i];
  39.                         }
  40.                         if (keymaterials[materials[i]] >= 250)
  41.                         {
  42.                             switch (materials[i])
  43.                             {
  44.                                 case "shards":
  45.                                     obtainedItem = "Shadowmourne";
  46.                                     break;
  47.                                 case "fragments":
  48.                                     obtainedItem = "Valanyr";
  49.                                     break;
  50.                                 case "motes":
  51.                                     obtainedItem = "Dragonwrath";
  52.                                     break;
  53.                             }
  54.                             Console.WriteLine($"{obtainedItem} obtained!");
  55.                             itemObtained = true;
  56.                             keymaterials[materials[i]] -= 250;
  57.                             break;
  58.                         }
  59.                     }
  60.                     else
  61.                     {
  62.                         if (junk.ContainsKey(materials[i]))
  63.                         {
  64.                             junk[materials[i]] += quantities[i];
  65.                         }
  66.                         else
  67.                             junk.Add(materials[i], quantities[i]);
  68.                     }
  69.                 }
  70.             }
  71.             foreach (var item in keymaterials.OrderByDescending(i => i.Value).ThenBy(i => i.Key))
  72.             {
  73.                 Console.WriteLine($"{item.Key}: {item.Value}");
  74.             }
  75.             foreach (var item in junk.OrderBy(i=>i.Key))
  76.             {
  77.                 Console.WriteLine($"{item.Key}: {item.Value}");
  78.             }
  79.         }
  80.     }
  81. }
Add Comment
Please, Sign In to add comment