Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace problem03
- {
- class Program
- {
- static void Main(string[] args)
- {
- Dictionary<string, List<int>> dict = new Dictionary<string, List<int>>();
- int capacity = int.Parse(Console.ReadLine());
- string comands = Console.ReadLine();
- while (comands != "Statistics")
- {
- string[] comand = comands.Split('=');
- if (comand[0] == "Add")
- {
- string username = comand[1];
- int sent = int.Parse(comand[2]);
- int received = int.Parse(comand[3]);
- int allMessages = sent + received;
- if (!dict.ContainsKey(username))
- {
- dict[username] = new List<int>();
- dict[username].Add(allMessages);
- dict[username].Add(received);
- }
- }
- else if (comand[0] == "Message")
- {
- string sender = comand[1];
- string receiver = comand[2];
- if (dict.ContainsKey(sender) && dict.ContainsKey(receiver))
- {
- dict[sender][0]++;
- dict[receiver][0]++;
- dict[receiver][1]++;
- if (dict[sender][0] >= capacity)
- {
- Console.WriteLine($"{sender} reached the capacity!");
- dict.Remove(sender);
- }
- if (dict[receiver][0] >= capacity)
- {
- Console.WriteLine($"{receiver} reached the capacity!");
- dict.Remove(receiver);
- }
- }
- }
- else if (comand[0] == "Empty")
- {
- if (comand[1] == "All")
- {
- dict = new Dictionary<string, List<int>>();
- }
- else
- {
- string username = comand[1];
- if (dict.ContainsKey(username))
- {
- dict.Remove(username);
- }
- }
- }
- comands = Console.ReadLine();
- }
- var countUserNames = dict.Keys.Count;
- Console.WriteLine($"Users count: {countUserNames}");
- var result = dict.OrderByDescending(x => x.Value[1]).ThenBy(x => x.Key);
- foreach (var item in result)
- {
- Console.WriteLine($"{item.Key} - {item.Value[0]}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment