Guest User

Untitled

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