Advertisement
Guest User

Untitled

a guest
Aug 1st, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Runtime.InteropServices.ComTypes;
  5.  
  6. namespace _3.Followers
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             var record = new Dictionary<string, Dictionary<string, int>>();
  13.             string input = String.Empty;
  14.             while ((input = Console.ReadLine()) != "Log out")
  15.             {
  16.                 string[] data = input.Split(": ");
  17.                 string command = data[0];
  18.                
  19.                 if (command.Contains("New follower"))
  20.                 {
  21.                     string username = data[1];
  22.                     if (!record.ContainsKey(username))
  23.                     {
  24.                         record.Add(username, new Dictionary<string, int>()
  25.                         {
  26.                             {"likes", 0 },
  27.                             {"comments", 0 }
  28.                         }
  29.                         );
  30.                     }
  31.                 }
  32.                 else if (command.Contains("Like"))
  33.                 {
  34.                     string username = data[1];
  35.                     int count = int.Parse(data[2]);
  36.                     if (!record.ContainsKey(username))
  37.                     {
  38.                         record.Add(username, new Dictionary<string, int>()
  39.                         {
  40.                             {"likes", count },
  41.                             {"comments", 0 }
  42.                         });
  43.                     }
  44.                     else
  45.                     {
  46.                         record[username]["likes"] += count;
  47.                         record[username]["comments"] += 0;
  48.                     }
  49.                 }
  50.                 else if (command.Contains("Comment"))
  51.                 {
  52.                     string username = data[1];
  53.                     if (!record.ContainsKey(username))
  54.                     {
  55.                         record.Add(username, new Dictionary<string, int>()
  56.                         {
  57.                             {"likes", 0},
  58.                             {"coments", 1}
  59.                            
  60.                         }) ;
  61.                     }
  62.                     else
  63.                     {
  64.                         record[username]["likes"] += 0;
  65.                         record[username]["comments"]++;
  66.                     }  
  67.                 }
  68.                 else if (command.Contains("Blocked"))
  69.                 {
  70.                     string username = data[1];
  71.                     if (!record.ContainsKey(username))
  72.                     {
  73.                         Console.WriteLine($"{username} doesn't exist");
  74.                     }
  75.                     else
  76.                     {
  77.                         record.Remove(username);
  78.                     }
  79.                 }
  80.             }
  81.             Console.WriteLine($"{record.Keys.Count} followers");
  82.             foreach (var user in record.OrderByDescending(x => x.Value["likes"]).ThenBy(x => x.Key))
  83.             {
  84.                 var sum = user.Value["likes"] + user.Value["comments"];
  85.                 Console.WriteLine($"{user.Key}: {sum}");
  86.             }
  87.         }
  88.     }
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement