Advertisement
miroLLL

Lora'sFanClub

Apr 24th, 2018
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.84 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ExamPreparation
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string inputInformation = string.Empty;
  12.  
  13.             Dictionary<string, Dictionary<string, int>> boysDatabase = new Dictionary<string, Dictionary<string, int>>();
  14.  
  15.             while ((inputInformation = Console.ReadLine()) != "Make a decision already!")
  16.             {
  17.                 string[] boyInfo = inputInformation.Split(" ", StringSplitOptions.RemoveEmptyEntries);
  18.  
  19.                 string boyName = boyInfo[0];
  20.  
  21.                 if ((boyInfo.Contains("does") && boyInfo.Contains("Gyubek!")) == false)
  22.                 {
  23.                     string trait = boyInfo[1];
  24.                     int traitValue = int.Parse(boyInfo[2]);
  25.  
  26.                     bool isNegativeBoy = trait.Equals("Greedy") || trait.Equals("Rude") || trait.Equals("Dumb");
  27.  
  28.                     if (isNegativeBoy == false) // Good boy.
  29.                     {
  30.                         switch (trait)
  31.                         {
  32.                             case "Kind":
  33.                                 traitValue *= 2;
  34.                                 break;
  35.                             case "Handsome":
  36.                                 traitValue *= 3;
  37.                                 break;
  38.                             case "Smart":
  39.                                 traitValue *= 5;
  40.                                 break;
  41.                         }
  42.                     }
  43.                     else
  44.                     {
  45.                         traitValue -= (traitValue * 2);
  46.                     }
  47.  
  48.                     if (boysDatabase.ContainsKey(boyName) == false)
  49.                     {
  50.                         boysDatabase.Add(boyName, new Dictionary<string, int>());
  51.                         boysDatabase[boyName].Add(trait, traitValue);
  52.                     }
  53.                     else
  54.                     {
  55.                         if (boysDatabase[boyName].ContainsKey(trait) == false)
  56.                         {
  57.                             boysDatabase[boyName].Add(trait, traitValue);
  58.                         }
  59.                         else
  60.                         {
  61.                             int oldTraitValue = boysDatabase[boyName][trait];
  62.  
  63.                             if(traitValue > oldTraitValue)
  64.                             {
  65.                                 boysDatabase[boyName][trait] = traitValue;
  66.                             }        
  67.                         }
  68.                     }
  69.                 }
  70.                 else if (boysDatabase.ContainsKey(boyName))
  71.                 {
  72.                     List<string> positiveTraits = new List<string>();
  73.  
  74.                     foreach (var gyubekBoy in boysDatabase[boyName])
  75.                     {
  76.                         if ((gyubekBoy.Key.Equals("Greedy") || gyubekBoy.Key.Equals("Rude") || gyubekBoy.Key.Equals("Dumb")) == false)
  77.                         {
  78.                             positiveTraits.Add(gyubekBoy.Key);
  79.                         }
  80.                     }
  81.  
  82.                     for (int i = 0; i < positiveTraits.Count; i++)
  83.                     {
  84.                         boysDatabase[boyName].Remove(positiveTraits[i]);
  85.                     }
  86.                 }
  87.             }
  88.  
  89.             foreach (var name in boysDatabase.OrderByDescending(x => x.Value.Select(y => y.Value).FirstOrDefault()).ThenBy(z => z.Key))
  90.             {
  91.                 int totalTraitValue = boysDatabase[name.Key].Values.Sum();
  92.  
  93.                 Console.WriteLine($"# {name.Key}: {totalTraitValue} ");
  94.  
  95.                 foreach (var trait in name.Value.OrderByDescending(x => x.Value).ThenBy(y => y.Key))
  96.                 {
  97.                     Console.WriteLine($"!!! {trait.Key} -> {trait.Value}");
  98.                 }
  99.             }
  100.         }
  101.     }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement