-
Notifications
You must be signed in to change notification settings - Fork 1
/
Program.cs
122 lines (107 loc) · 5.36 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace _09.LegendaryFarming
{
class Program
{
static void Main(string[] args)
{
var keyMaterialsQuantity = new SortedDictionary<string, int>();
var junkMaterialsQuantity = new SortedDictionary<string, int>();
keyMaterialsQuantity.Add("shards", 0);
keyMaterialsQuantity.Add("fragments", 0);
keyMaterialsQuantity.Add("motes", 0);
while (true)
{
var inputLine = Console.ReadLine().ToLower().Split().ToList();
var quantitiesEnteredMaterials = inputLine.Where((str, index) => index % 2 == 0).Select(str => str)
.Select(str => int.Parse(str)).ToList();
var namesEnteredMaterials = inputLine.Where((str, index) => index % 2 == 1).Select(str => str).ToList();
for (int i = 0; i < namesEnteredMaterials.Count; i++)
{
var nameCurrentMaterial = namesEnteredMaterials[i];
var quantityCurrentMaterial = quantitiesEnteredMaterials[i];
if (nameCurrentMaterial == "shards")
{
//keyMaterialsQuantity
AddCurrentKeyMaterialQuantityInStock(keyMaterialsQuantity, nameCurrentMaterial, quantityCurrentMaterial);
if (keyMaterialsQuantity[nameCurrentMaterial] >= 250)
{
Console.WriteLine("Shadowmourne obtained!");
keyMaterialsQuantity[nameCurrentMaterial] -= 250;
//print left material and quantity
PrintLeftMaterialsAndQuantity(keyMaterialsQuantity, junkMaterialsQuantity);
return;
}
}
else if (nameCurrentMaterial == "fragments")
{
//keyMaterialsQuantity
AddCurrentKeyMaterialQuantityInStock(keyMaterialsQuantity, nameCurrentMaterial, quantityCurrentMaterial);
if (keyMaterialsQuantity[nameCurrentMaterial] >= 250)
{
Console.WriteLine("Valanyr obtained!");
keyMaterialsQuantity[nameCurrentMaterial] -= 250;
//print left material and quantity
PrintLeftMaterialsAndQuantity(keyMaterialsQuantity, junkMaterialsQuantity);
return;
}
}
else if (nameCurrentMaterial == "motes")
{
//keyMaterialsQuantity
AddCurrentKeyMaterialQuantityInStock(keyMaterialsQuantity, nameCurrentMaterial, quantityCurrentMaterial);
if (keyMaterialsQuantity[nameCurrentMaterial] >= 250)
{
Console.WriteLine("Dragonwrath obtained!");
keyMaterialsQuantity[nameCurrentMaterial] -= 250;
//print left material and quantity
PrintLeftMaterialsAndQuantity(keyMaterialsQuantity, junkMaterialsQuantity);
return;
}
}
else
{
//junkMaterialsQuantity
AddCurrentJunkMaterialQuantity(junkMaterialsQuantity, nameCurrentMaterial, quantityCurrentMaterial);
}
}
}
}
static void PrintLeftMaterialsAndQuantity(SortedDictionary<string, int> keyMaterialsQuantity, SortedDictionary<string, int> junkMaterialsQuantity)
{
foreach (var keyMaterialQuantity in keyMaterialsQuantity.OrderByDescending(quantity => quantity.Value))
{
Console.WriteLine($"{keyMaterialQuantity.Key}: {keyMaterialQuantity.Value}");
}
foreach (var junkMaterialQuantity in junkMaterialsQuantity)
{
Console.WriteLine($"{junkMaterialQuantity.Key}: {junkMaterialQuantity.Value}");
}
}
static void AddCurrentJunkMaterialQuantity(SortedDictionary<string, int> junkMaterialsQuantity,
string nameCurrentMaterial, int quantityCurrentMaterial)
{
if (!junkMaterialsQuantity.ContainsKey(nameCurrentMaterial))
{
junkMaterialsQuantity.Add(nameCurrentMaterial, quantityCurrentMaterial);
}
else
{
var quantityInStock = junkMaterialsQuantity[nameCurrentMaterial];
var totalQuantity = quantityInStock + quantityCurrentMaterial;
junkMaterialsQuantity[nameCurrentMaterial] = totalQuantity;
}
}
static void AddCurrentKeyMaterialQuantityInStock(SortedDictionary<string, int> keyMaterialsQuantity,
string nameCurrentMaterial, int quantityCurrentMaterial)
{
var quantityInStock = keyMaterialsQuantity[nameCurrentMaterial];
var totalQuantity = quantityInStock + quantityCurrentMaterial;
keyMaterialsQuantity[nameCurrentMaterial] = totalQuantity;
}
}
}