Advertisement
veno0

Untitled

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