Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- using System.Text;
- using System.Text.RegularExpressions;
- class Program
- {
- static void Main()
- {
- int macCapacity = int.Parse(Console.ReadLine());
- Dictionary<string, Dictionary<string, int>> users = new Dictionary<string, Dictionary<string, int>>();
- string command = Console.ReadLine();
- while (command != "Statistics")
- {
- string[] line = command.Split("=");
- string cmd = line[0];
- if (cmd == "Add")
- {
- string userName = line[1];
- int sendMessages = int.Parse(line[2]);
- int receivedMessages = int.Parse(line[3]);
- if (!users.ContainsKey(userName))
- {
- users.Add(userName, new Dictionary<string, int>()
- {
- {"send", sendMessages },
- {"received", receivedMessages }
- });
- }
- }
- else if (cmd == "Message")
- {
- string sender = line[1];
- string receiver = line[2];
- if (users.ContainsKey(sender) && users.ContainsKey(receiver))
- {
- users[sender]["send"] += 1;
- users[receiver]["received"] += 1;
- if (users[sender]["send"] + users[sender]["received"] >= macCapacity)
- {
- Console.WriteLine($"{sender} reached the capacity!");
- users.Remove(sender);
- }
- if (users[receiver]["received"] + users[receiver]["send"] >= macCapacity)
- {
- Console.WriteLine($"{receiver} reached the capacity!");
- users.Remove(receiver);
- }
- }
- }
- else if (cmd == "Empty")
- {
- if (line[1] == "All")
- {
- foreach (var item in users)
- {
- users.Remove(item.Key);
- }
- }
- else
- {
- string user = line[1];
- users.Remove(user);
- }
- }
- command = Console.ReadLine();
- }
- foreach (var item in users)
- {
- if (item.Value["send"] == 0 && item.Value["received"] == 0)
- {
- users.Remove(item.Key);
- }
- }
- users = users
- .OrderByDescending(s => s.Value["received"])
- .ThenBy(s => s.Key)
- .ToDictionary(s => s.Key, x => x.Value);
- Console.WriteLine($"Users count: {users.Count}");
- foreach (var item in users)
- {
- int totalPoints = item.Value["send"] + item.Value["received"];
- string userName = item.Key;
- Console.WriteLine($"{userName} - {totalPoints}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement