Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _01.Template
- {
- class Program
- {
- static void Main(string[] args)
- {
- //keeps the key materials
- var keyMat = new Dictionary<string, int>()
- {
- {"fragments", 0},
- {"motes", 0},
- {"shards", 0}
- };
- //keeps the junk materials
- var junkMat = new SortedDictionary<string, int>();
- //bool to check if we found a legendary. Finds use later to break out of the while loop.
- bool isFound = false;
- //we're getting the farming goods line by line, we're stopping when we
- //obtain a legendary.
- while (true)
- {
- string mainInput = Console.ReadLine().ToLower();
- //since the input comes as a big wall of text, containing the
- //materials and their quantity, we have to split it in order to
- //populate a Dictionary:
- //arr which will split the mainInput and fill the list I'm about
- //to declare.
- string[] arr = mainInput.Split(" ");
- List<string> list = new List<string>();
- //index steps += 2, because the input is given as <material><quantity><material><quantity> etc..
- for (int i = 0; i < arr.Length; i += 2)
- {
- list.Add(arr[i] + " " + arr[i + 1]);
- }
- for (int farming = 0; farming < list.Count; farming++)
- {
- string[] farmed = list[farming].Split(" ").ToArray();
- string material = farmed[1];
- int quantity = int.Parse(farmed[0]);
- if (material.Equals("motes") || material.Equals("fragments")
- || material.Equals("shards"))
- {
- if (!keyMat.ContainsKey(material))
- {
- keyMat.Add(material, quantity);
- }
- else
- {
- keyMat[material] += quantity;
- }
- if (keyMat[material] >= 250)
- {
- //Check what material contains more than 250 elements and printing the obtained
- //legendary, reducing the material quantity after obtaining the item.
- if (material.Equals("motes"))
- {
- Console.WriteLine("Dragonwrath obtained!");
- }
- else if (material.Equals("shards"))
- {
- Console.WriteLine("Shadowmourne obtained!");
- }
- else if (material.Equals("fragments"))
- {
- Console.WriteLine("Valanyr obtained!");
- }
- keyMat[material] -= 250;
- isFound = true;
- break;
- }
- }
- else
- {
- if (!junkMat.ContainsKey(material))
- {
- junkMat.Add(material, quantity);
- }
- else
- {
- junkMat[material] += quantity;
- }
- }
- }
- if (isFound)
- {
- break;
- }
- }
- //order by descending order by quantity, if two keys quantity equal -> order alphabetically
- foreach (var item in keyMat.OrderByDescending(x => x.Value).ThenBy(y => y.Key))
- {
- string material = item.Key;
- int quantity = item.Value;
- Console.WriteLine($"{material}: {quantity}");
- }
- foreach (var item in junkMat)
- {
- string material = item.Key;
- int quantity = item.Value;
- Console.WriteLine($"{material}: {quantity}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement