Advertisement
Guest User

Legendary_Farming

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