Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _04P.Snowwhite
- {
- public class Snowwhite
- {
- public static void Main()
- {
- Solution1();
- //Solution2();
- }
- private static void Solution2()
- {
- var data = new Dictionary<string, Dictionary<string, int>>();
- string input = Console.ReadLine();
- while (input != "Once upon a time")
- {
- var dwarfInfo = input.Split("<:> ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries).ToList();
- string color = dwarfInfo[1];
- string name = dwarfInfo[0];
- int physics = int.Parse(dwarfInfo[2]);
- if (!data.ContainsKey(color))
- {
- data.Add(color, new Dictionary<string, int>());
- data[color][name] = physics;
- }
- else if (!data[color].ContainsKey(name))
- {
- data[color].Add(name, physics);
- }
- if (data[color][name] < physics)
- {
- data[color][name] = physics;
- }
- input = Console.ReadLine();
- }
- foreach (var color in data.OrderByDescending(x => x.Value.Values.Max()).ThenByDescending(x => x.Value.Count()))
- {
- var dwarfs = color.Value;
- foreach (var dwarf in dwarfs)
- {
- Console.Write($"({color.Key}) ");
- Console.WriteLine($"{dwarf.Key} <-> {dwarf.Value}");
- }
- }
- }
- private static void Solution1()
- {
- string text = Console.ReadLine();
- Dictionary<string, Dictionary<string, int>> dict = new Dictionary<string, Dictionary<string, int>>();
- while (text != "Once upon a time")
- {
- string[] input = text
- .Split(new char[] { ',', ' ', '<', ':', '>' }, StringSplitOptions.RemoveEmptyEntries);
- string name = input[0].Trim();
- string color = input[1].Trim();
- int phys = int.Parse(input[2]);
- if (!dict.ContainsKey(color))
- {
- dict.Add(color, new Dictionary<string, int>());
- dict[color][name] = phys;
- }
- else if (!dict[color].ContainsKey(name))
- {
- dict[color].Add(name, phys);
- }
- if (dict[color][name] < phys)
- {
- dict[color][name] = phys;
- }
- text = Console.ReadLine();
- }
- foreach (var kvp in dict)
- {
- foreach (var item in kvp.Value)
- {
- Console.Write($"({kvp.Key}) ");
- Console.WriteLine($"{item.Key} <-> {item.Value}");
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement