9. * Legendary Farming ??? 60/100 ЗАЩО!?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _09.Legendary_Farming
{
class Program
{
public static Dictionary<string, int> keyMaterials = new Dictionary<string, int>();
public static SortedDictionary<string, int> junk = new SortedDictionary<string, int>();
static void Main(string[] args)
{
keyMaterials.Add("shards", 0);
keyMaterials.Add("fragments", 0);
keyMaterials.Add("motes", 0);
while (!enoughMaterials())
{
string[] line = Console.ReadLine().ToLower().Split(' ').ToArray();
for (int i = 0; i < line.Length; i += 2)
{
int quantity = int.Parse(line[i]);
string material = line[i + 1];
if (keyMaterials.ContainsKey(material))
{
keyMaterials[material] += quantity;
}
else if (junk.ContainsKey(material))
{
junk[material] += quantity;
}
else
{
junk.Add(material, quantity);
}
if (enoughMaterials())
{
break;
}
}
}
PrintLegendary();
foreach (var item in keyMaterials.OrderByDescending(x => x.Value).ThenBy(x=>x.Key))
{
Console.WriteLine($"{item.Key}: {item.Value}");
}
foreach (var item in junk)
{
Console.WriteLine($"{item.Key}: {item.Value}");
}
}
private static void PrintLegendary()
{
if (keyMaterials["shards"] >= 250)
{
Console.WriteLine("Shadowmourne obtained!");
keyMaterials["shards"] -= 250;
}
else if (keyMaterials["fragments"] >= 250)
{
Console.WriteLine("Valanyr obtained!");
keyMaterials["fragments"] -= 250;
}
else
{
Console.WriteLine("Dragonwrath obtained!");
keyMaterials["motes"] -= 250;
}
}
public static bool enoughMaterials()
{
if (keyMaterials.Values.Any(x => x >= 250))
{
return true;
}
return false;
}
}
}
Много благодаря!!! Никога нямаше да се сетя.