Advertisement
Guest User

Untitled

a guest
Nov 22nd, 2020
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5.  
  6. namespace _03._Legendary_Farming
  7. {
  8.     class Program
  9.     {
  10.         static void Main()
  11.         {
  12.             Dictionary<string, int> dict = new Dictionary<string, int>();
  13.             StringBuilder strb = new StringBuilder();
  14.  
  15.             bool isDone = false;
  16.             while (!isDone)
  17.             {
  18.                 string[] words = Console.ReadLine().Split();
  19.  
  20.                 int value = 0;
  21.                 string key;
  22.  
  23.  
  24.                 for (int i = 0; i < words.Length && !isDone; i++)
  25.                 {
  26.                     if ((i + 1) % 2 != 0)
  27.                     {
  28.                         value = int.Parse(words[i]);
  29.                     }
  30.                     else
  31.                     {
  32.                         key = words[i].ToLower();
  33.  
  34.                         if (dict.ContainsKey(key))
  35.                         {
  36.                             dict[key] += value;
  37.                         }
  38.                         else
  39.                         {
  40.                             dict.Add(key, value);
  41.                         }
  42.  
  43.                         if (dict[key] > 249 && (key == "shards" || key == "fragments" || key == "motes"))
  44.                         {
  45.                             if (key == "shards")
  46.                             {
  47.                                 strb.AppendLine("Shadowmourne obtained!");
  48.                             }
  49.                             else if (key == "fragments")
  50.                             {
  51.                                 strb.AppendLine("Valanyr obtained!");
  52.                             }
  53.                             else
  54.                             {
  55.                                 strb.AppendLine("Dragonwrath obtained!");
  56.                             }
  57.  
  58.                             dict[key] -= 250;
  59.                             isDone = true;
  60.                         }
  61.                     }
  62.                 }
  63.             }
  64.  
  65.             if (!dict.ContainsKey("fragments"))
  66.             {
  67.                 dict.Add("fragments", 0);
  68.             }
  69.             else if (!dict.ContainsKey("shards"))
  70.             {
  71.                 dict.Add("shards", 0);
  72.             }
  73.             else if (!dict.ContainsKey("motes"))
  74.             {
  75.                 dict.Add("motes", 0);
  76.             }
  77.  
  78.             var keyMaterials = dict.Where(x => x.Key == "shards" || x.Key == "fragments" || x.Key == "motes")
  79.                 .OrderByDescending(x => x.Value).ThenBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
  80.  
  81.  
  82.             foreach (var item in keyMaterials)
  83.             {
  84.                 strb.AppendLine($"{item.Key}: {item.Value}");
  85.                 dict.Remove(item.Key);
  86.             }
  87.  
  88.             var junkDict = dict.OrderBy(x => x.Key).ToDictionary(x => x.Key, y => y.Value);
  89.  
  90.             foreach (var item in junkDict)
  91.             {
  92.                 strb.AppendLine($"{item.Key}: {item.Value}");
  93.             }
  94.  
  95.             Console.WriteLine(strb.ToString());
  96.         }
  97.     }
  98. }
  99.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement