Advertisement
Primaxm

Problem 4 Snowwhite

May 26th, 2018
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.18 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Numerics;
  5.  
  6. namespace Snowwhite
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             string input = Console.ReadLine();
  13.             List<Dwarf> dwarf = new List<Dwarf>();
  14.  
  15.             while (input != "Once upon a time")
  16.             {
  17.                 string[] splitedInput = input.Split(new string[] { " <:> " }, StringSplitOptions.None);
  18.  
  19.  
  20.                 string dwarfName = splitedInput[0];
  21.                 string dwarfColor = splitedInput[1];
  22.                 BigInteger dwarfPhysics = BigInteger.Parse(splitedInput[2]);
  23.  
  24.                 Dwarf dd = new Dwarf();
  25.  
  26.                 dd.Color = dwarfColor;
  27.                 dd.Name = dwarfName;
  28.                 dd.Physics = dwarfPhysics;
  29.  
  30.                 bool contains = false;
  31.                 for (int i = 0; i < dwarf.Count; i++)
  32.                 {
  33.                     if (dwarf[i].Name == dd.Name && dwarf[i].Color == dd.Color)
  34.                     {
  35.                         if (dwarf[i].Physics < dd.Physics) dwarf[i].Physics = dd.Physics;
  36.                         contains = true;
  37.                     }
  38.                 }
  39.  
  40.  
  41.                 if (!contains)
  42.                 {
  43.                     int count = dwarf.Where(x => x.Color == dwarfColor).Count() + 1;
  44.                     dd.ColorCount = count;
  45.                     dwarf.Add(dd);
  46.                     foreach (var item in dwarf.Where(x => x.Color == dwarfColor))
  47.                     {
  48.                         item.ColorCount = count;
  49.                     }
  50.                 }
  51.  
  52.                 input = Console.ReadLine();
  53.             }
  54.  
  55.             var tmpDwarf = dwarf;
  56.  
  57.             foreach (var item in dwarf.OrderByDescending(z => z.Physics).ThenByDescending(z => z.ColorCount))
  58.                 {
  59.                 Console.WriteLine($"({item.Color}) {item.Name} <-> {item.Physics}");
  60.             }
  61.         }
  62.  
  63.         class Dwarf
  64.         {
  65.             public string Color { get; set; }
  66.             public string Name { get; set; }
  67.             public BigInteger Physics { get; set; }
  68.             public int ColorCount { get; set; }
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement