Advertisement
Guest User

Untitled

a guest
Apr 27th, 2018
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. class p04_LorasFanClub
  6. {
  7.     static void Main()
  8.     {
  9.         Dictionary<string, Dictionary<string, int>> fans = new Dictionary<string, Dictionary<string, int>>();
  10.  
  11.         string input;
  12.         while ((input = Console.ReadLine()) != "Make a decision already!")
  13.         {
  14.             string[] tokens = input.Split();
  15.             string name = tokens[0];
  16.  
  17.             if (!input.Contains("does Gyubek!"))
  18.             {
  19.                 string trait = tokens[1];
  20.                 int value = int.Parse(tokens[2]);
  21.  
  22.                 if (!fans.ContainsKey(name))
  23.                 {
  24.                     fans.Add(name, new Dictionary<string, int>());
  25.                 }
  26.  
  27.                 if (fans[name].ContainsKey(trait))
  28.                 {
  29.                     if (fans[name][trait] < value)
  30.                     {
  31.                         fans[name][trait] = AddValue(trait, value);
  32.                     }
  33.                 }
  34.                 else
  35.                 {
  36.                     fans[name].Add(trait, AddValue(trait, value));
  37.                 }
  38.             }
  39.             else
  40.             {
  41.                 if (fans.ContainsKey(name))
  42.                 {
  43.                     fans[name].Clear();
  44.                 }
  45.             }
  46.         }
  47.  
  48.         foreach (var boy in fans.OrderByDescending(x => x.Value.Values.Sum()).ThenBy(x => x.Key))
  49.         {
  50.             Console.WriteLine($"# {boy.Key}: {boy.Value.Values.Sum()}");
  51.             foreach (var trait in boy.Value.OrderByDescending(x => x.Value))
  52.             {
  53.                 Console.WriteLine($"!!! {trait.Key} -> {trait.Value}");
  54.             }
  55.         }
  56.     }
  57.  
  58.     static int AddValue(string trait, int value)
  59.     {
  60.         switch (trait)
  61.         {
  62.             case "Greedy":
  63.             case "Rude":
  64.             case "Dumb":
  65.                 value *= -1;
  66.                 break;
  67.             case "Kind":
  68.                 value *= 2;
  69.                 break;
  70.             case "Handsome":
  71.                 value *= 3;
  72.                 break;
  73.             case "Smart":
  74.                 value *= 5;
  75.                 break;
  76.             default:
  77.                 return value;              
  78.         }
  79.         return value;
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement