veno0

Untitled

Mar 30th, 2020
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.80 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;
  14.                 Dictionary<string,int[]> users = new Dictionary<string, int[]>();
  15.                 int counUsers = 0;
  16.                 while ((input = Console.ReadLine()) != "Log out" )
  17.  
  18.                 {
  19.                     string[] splitted = input.Split(": ");
  20.                     string command = splitted[0];
  21.                     string username = splitted[1];
  22.  
  23.                     if (command == "New follower")
  24.                     {
  25.                         if (!users.ContainsKey(username))
  26.                         {
  27.                             users.Add(username,new int[2]);
  28.                             counUsers++;
  29.                         }
  30.                     }
  31.                     else if (command == "Like")
  32.                     {
  33.                         int likes = int.Parse(splitted[2]);
  34.                         if (!users.ContainsKey(username))
  35.                         {
  36.                             users.Add(username,new int[2]{likes,0});
  37.                            
  38.                             counUsers++;
  39.  
  40.                         }
  41.                         else
  42.                         {
  43.                             users[username][0] += likes;
  44.  
  45.                         }
  46.                     }
  47.                     else if (command == "Comment")
  48.                     {
  49.                         if (!users.ContainsKey(username))
  50.                         {
  51.                             users.Add(username,new int[2]{0,1});
  52.                            
  53.                             counUsers++;
  54.                         }
  55.                         else
  56.                         {
  57.                             users[username][1]++;
  58.                         }
  59.                     }
  60.                     else if (command == "Blocked")
  61.                     {
  62.                         if (!users.ContainsKey(username))
  63.                         {
  64.                             Console.WriteLine("{Username} doesn't exist.");
  65.                         }
  66.                         else
  67.                         {
  68.                             users.Remove(username);
  69.                             counUsers--;
  70.                         }
  71.                     }
  72.                    
  73.  
  74.                 }
  75.                 Console.WriteLine($"{users.Count} followers");
  76.                 foreach (var user in users.OrderByDescending(x=>x.Value[0]).ThenBy(x=>x.Key))
  77.                 {
  78.                     Console.WriteLine($"{user.Key}: {user.Value[0] + user.Value[1]}");
  79.                 }
  80.             }
  81.         }
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment