Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 08.Legendary Farming
- You’ve done all the work and the last thing left to accomplish is to own a legendary item. However, it’s a tedious process and it requires quite a bit of farming. Anyway, you are not too pretentious – any legendary item will do. The possible items are:
- • Shadowmourne – requires 250 Shards;
- • Valanyr – requires 250 Fragments;
- • Dragonwrath – requires 250 Motes;
- Shards, Fragments and Motes are the key materials and everything else is junk. You will be given lines of input, in the format:
- 2 motes 3 ores 15 stones
- Keep track of the key materials - the first one that reaches the 250 mark, wins the race. At that point you have to print that the corresponding legendary item is obtained. Then, print the remaining shards, fragments, motes, ordered by quantity in descending order, then by name in ascending order, each on a new line. Finally, print the collected junk items in alphabetical order.
- Input
- • Each line comes in the following format: {quantity} {material} {quantity} {material} … {quantity} {material}
- Output
- • On the first line, print the obtained item in the format: {Legendary item} obtained!
- • On the next three lines, print the remaining key materials in descending order by quantity
- o If two key materials have the same quantity, print them in alphabetical order
- • On the final several lines, print the junk items in alphabetical order
- o All materials are printed in format {material}: {quantity}
- o The output should be lowercase, except for the first letter of the legendary
- Examples
- Input Output
- 3 Motes 5 stones 5 Shards Valanyr obtained!
- 6 leathers 255 fragments 7 Shards fragments: 5
- shards: 5
- motes: 3
- leathers: 6
- stones: 5
- 123 silver 6 shards 8 shards 5 motes Dragonwrath obtained!
- 9 fangs 75 motes 103 MOTES 8 Shards shards: 22
- 86 Motes 7 stones 19 silver motes: 19
- fragments: 0
- fangs: 9
- silver: 123
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace _03LegendaryFarming
- {
- class Program
- {
- static void Main(string[] args)
- {
- var materials = new Dictionary<string, int>();
- var legendaryItem = new[] { "shards", "fragments", "motes" };
- materials.Add(legendaryItem[0], 0);
- materials.Add(legendaryItem[1], 0);
- materials.Add(legendaryItem[2], 0);
- var junk = new Dictionary<string, int>();
- var quantity = 0;
- var name = "";
- while (materials["shards"] < 250 && materials["fragments"] < 250 && materials["motes"] < 250)
- {
- var input = Console.ReadLine().ToLower().Split();
- /*for (int i = 1; i <= input.Length; i += 2)// По-кратко решение!
- {
- quantity = int.Parse(input[i]);
- var material = input[i + 1];
- switch (material)
- {
- case "shards":
- case "fragments":
- case "motes":
- materials[material] += quantity;
- break;
- default:
- if (!junk.ContainsKey(material))
- junk.Add(material, 0);
- junk[material] += quantity;
- break;
- }
- if (materials["shards"] >= 250 || materials["fragments"] >= 250 || materials["motes"] >= 250)
- break;
- }
- if (materials["shards"] >= 250)
- {
- name = "Shadowmourne";
- materials["shards"] -= 250;
- }
- else if (materials["fragments"] >= 250)
- {
- name = "Valanyr";
- materials["fragments"] -= 250;
- }
- else
- {
- name = "Dragonwrath";
- materials["motes"] -= 250;
- }
- Console.WriteLine($"{name} obtained!");
- foreach (var item in materials.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{item.Key}: {item.Value}");
- }
- foreach (var item in junk.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{item.Key}: {item.Value}");
- }*/
- foreach (var item in input)
- {
- if (char.IsDigit(item[0]) == true)
- {
- quantity = int.Parse(item);
- continue;
- }
- if (item == "shards")
- {
- if (materials.ContainsKey(item))
- {
- materials[item] += quantity;
- if (materials[item] >= 250)
- {
- materials[item] -= 250;
- name = "Shadowmourne";
- Console.WriteLine($"{name} obtained!");
- foreach (var order in materials.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{order.Key}: {order.Value}");
- }
- foreach (var order in junk.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{order.Key}: {order.Value}");
- }
- return; ;
- }
- }
- }
- else if (item == "fragments")
- {
- if (materials.ContainsKey(item))
- {
- materials[item] += quantity;
- if (materials[item] >= 250)
- {
- materials[item] -= 250;
- name = "Valanyr";
- Console.WriteLine($"{name} obtained!");
- foreach (var order in materials.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{order.Key}: {order.Value}");
- }
- foreach (var order in junk.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{order.Key}: {order.Value}");
- }
- return;
- }
- }
- }
- else if (item == "motes")
- {
- if (materials.ContainsKey(item))
- {
- materials[item] += quantity;
- if (materials[item] >= 250)
- {
- materials[item] -= 250;
- name = "Dragonwrath";
- Console.WriteLine($"{name} obtained!");
- foreach (var order in materials.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- {
- Console.WriteLine($"{order.Key}: {order.Value}");
- }
- foreach (var order in junk.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{order.Key}: {order.Value}");
- }
- return;
- }
- }
- }
- else
- {
- if (junk.ContainsKey(item))
- {
- junk[item] += quantity;
- }
- else
- {
- junk.Add(item, quantity);
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment