-
Notifications
You must be signed in to change notification settings - Fork 0
/
Snowwhite.cs
44 lines (41 loc) · 1.36 KB
/
Snowwhite.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
using System;
using System.Collections.Generic;
using System.Linq;
namespace Snowwhite
{
class Program
{
static void Main(string[] args)
{
var dwarfs = new Dictionary<string, int>();
string input = Console.ReadLine();
while (input != "Once upon a time")
{
string[] inputs = input.Split(new string[] { " <:> " }, StringSplitOptions.None);
string name = inputs[0];
string color = inputs[1];
int physics = int.Parse(inputs[2]);
string ID = name + ":" + color;
if (!dwarfs.ContainsKey(ID))
{
dwarfs.Add(ID, physics);
}
else
{
dwarfs[ID] = Math.Max(dwarfs[ID], physics);
}
input = Console.ReadLine();
}
foreach (var dwarf in dwarfs
.OrderByDescending(x => x.Value)
.ThenByDescending(x => dwarfs.Where(y => y.Key.Split(':')[1] == x.Key.Split(':')[1])
.Count()))
{
Console.WriteLine("({0}) {1} <-> {2}",
dwarf.Key.Split(':')[1],
dwarf.Key.Split(':')[0],
dwarf.Value);
}
}
}
}