kalitarix

V-logger

Nov 29th, 2018
1,429
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.24 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Vlogger
  6. {
  7.     class Vlogger
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Dictionary<string, Dictionary<string, HashSet<string>>> database = new Dictionary<string, Dictionary<string, HashSet<string>>>();
  12.  
  13.             string input = Console.ReadLine();
  14.  
  15.             while (input != "Statistics")
  16.             {
  17.                 string[] data = input.Split();
  18.  
  19.                 string vlogger = data[0];
  20.                 string command = data[1];
  21.  
  22.                 if (command == "joined")
  23.                 {
  24.                     if (database.ContainsKey(vlogger) == false)
  25.                     {
  26.                         database.Add(vlogger, new Dictionary<string, HashSet<string>>());
  27.                         database[vlogger].Add("followers", new HashSet<string>());
  28.                         database[vlogger].Add("following", new HashSet<string>());
  29.                     }
  30.                 }
  31.                 else if (command == "followed")
  32.                 {
  33.                     string member = data[2];
  34.  
  35.                     if (vlogger != member && database.ContainsKey(vlogger) && database.ContainsKey(member))
  36.                     {
  37.                         database[vlogger]["following"].Add(member);
  38.                         database[member]["followers"].Add(vlogger);
  39.                     }
  40.                 }
  41.  
  42.                 input = Console.ReadLine();
  43.             }
  44.  
  45.             Console.WriteLine($"The V-Logger has a total of {database.Count} vloggers in its logs.");
  46.  
  47.             int number = 1;
  48.  
  49.             foreach (var vlogger in database.OrderByDescending(v => v.Value["followers"].Count).ThenBy(v => v.Value["following"].Count))
  50.             {
  51.                 Console.WriteLine($"{number}. {vlogger.Key} : {vlogger.Value["followers"].Count} followers, {vlogger.Value["following"].Count} following");
  52.  
  53.                 if (number == 1)
  54.                 {
  55.                     foreach (string follower in vlogger.Value["followers"].OrderBy(f => f))
  56.                     {
  57.                         Console.WriteLine($"*  {follower}");
  58.                     }
  59.                 }
  60.  
  61.                 number++;
  62.             }
  63.         }
  64.     }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment