Advertisement
nikolapetkov824

theVlogger

Feb 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.88 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace P07TheVlogger
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var usernames = new HashSet<string>();
  12.             var howManyFollowersUsersHave = new Dictionary<string, HashSet<string>>();
  13.             var following = new Dictionary<string, HashSet<string>>();
  14.  
  15.             while (true)
  16.             {
  17.                 string input = Console.ReadLine();
  18.  
  19.                 if (input == "Statistics")
  20.                 {
  21.                     break;
  22.                 }
  23.                 else
  24.                 {
  25.                     string[] commandsInfo = input
  26.                             .Split(" ", StringSplitOptions.RemoveEmptyEntries);
  27.  
  28.                     string name = commandsInfo[0];
  29.  
  30.                     if (commandsInfo.Length == 4)
  31.                     {
  32.                         string command = commandsInfo[1];
  33.                         string vloggerClub = commandsInfo[3];
  34.  
  35.                         usernames.Add(name);
  36.  
  37.                         if (usernames.Contains(name))
  38.                         {
  39.                             if (howManyFollowersUsersHave.ContainsKey(name) == false)
  40.                             {
  41.                                 howManyFollowersUsersHave.Add(name, new HashSet<string>());
  42.                             }
  43.  
  44.                             if (following.ContainsKey(name) == false)
  45.                             {
  46.                                 following.Add(name, new HashSet<string>());
  47.                             }
  48.                         }
  49.                     }
  50.                     else if (commandsInfo.Length == 3)
  51.                     {
  52.                         string command = commandsInfo[1];
  53.                         string vlogger = commandsInfo[2];
  54.  
  55.                         if (usernames.Contains(name)
  56.                             && usernames.Contains(vlogger)
  57.                             && name != vlogger)
  58.                         {
  59.                             if (howManyFollowersUsersHave.ContainsKey(vlogger) == false)
  60.                             {
  61.                                 howManyFollowersUsersHave.Add(vlogger, new HashSet<string>());
  62.                             }
  63.  
  64.                             howManyFollowersUsersHave[vlogger].Add(name);
  65.  
  66.                             if (following.ContainsKey(name) == false)
  67.                             {
  68.                                 following.Add(name, new HashSet<string>());
  69.                             }
  70.  
  71.                             following[name].Add(vlogger);
  72.                         }
  73.                     }
  74.                 }
  75.             }
  76.  
  77.             int count = 2;
  78.  
  79.             Console.WriteLine($"The V-Logger has a total of {usernames.Count} vloggers in its logs.");
  80.  
  81.             var topUser = howManyFollowersUsersHave
  82.                 .OrderByDescending(x => x.Value.Count)
  83.                 .ThenBy(g => following[g.Key].Count)
  84.                 .FirstOrDefault();
  85.  
  86.             Console.WriteLine($"1. {topUser.Key} : {topUser.Value.Count} followers, {following[topUser.Key].Count} following");
  87.  
  88.             foreach (var followers in topUser.Value.OrderBy(x=>x))
  89.             {
  90.                 Console.WriteLine($"*  {followers}");
  91.             }
  92.  
  93.             foreach (var user in howManyFollowersUsersHave
  94.                 .Where(y=>y.Key != topUser.Key)
  95.                 .OrderByDescending(x => x.Value.Count)
  96.                 .ThenBy(y => following[y.Key].Count))
  97.             {
  98.                 foreach (var item in following)
  99.                 {
  100.                     if (user.Key == item.Key)
  101.                     {
  102.                         Console.WriteLine($"{count}. {user.Key} : {user.Value.Count} followers, {item.Value.Count} following");
  103.                         count++;
  104.                     }
  105.                 }
  106.             }
  107.         }
  108.     }
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement