Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- namespace ConsoleApp4
- {
- class Program
- {
- static void Main(string[] args)
- {
- int capacity = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- Dictionary<string, int> sentMessages = new Dictionary<string, int>();
- Dictionary<string, int> recievedMessages = new Dictionary<string, int>();
- while (input != "Statistics")
- {
- string[] tokens = input.Split('=').ToArray();
- if (tokens[0] == "Add")
- {
- if (sentMessages.ContainsKey(tokens[0]) && recievedMessages.ContainsKey(tokens[0]))
- {
- continue;
- }
- else
- {
- int sent = int.Parse(tokens[2]);
- int recieved = int.Parse(tokens[3]);
- sentMessages.Add(tokens[1], sent);
- recievedMessages.Add(tokens[1], recieved);
- }
- }
- else if (tokens[0] == "Message")
- {
- if (sentMessages.ContainsKey(tokens[1]) && recievedMessages.ContainsKey(tokens[2]))
- {
- sentMessages[tokens[1]]++;
- recievedMessages[tokens[2]]++;
- if (sentMessages[tokens[1]] == capacity)
- {
- Console.WriteLine($"{tokens[1]} reached the capacity!");
- sentMessages.Remove(tokens[1]);
- }
- else if (recievedMessages[tokens[2]] == capacity)
- {
- Console.WriteLine($"{tokens[2]} reached the capacity!");
- recievedMessages.Remove(tokens[2]);
- }
- }
- }
- else if (tokens[0] == "Empty")
- {
- if (tokens[1] == "All")
- {
- sentMessages.Clear();
- recievedMessages.Clear();
- }
- else
- {
- sentMessages.Remove(tokens[1]);
- recievedMessages.Remove(tokens[1]);
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"Users count: {sentMessages.Count}");
- recievedMessages.OrderByDescending(x => x.Value);
- foreach (var user in sentMessages.OrderBy(x => x.Key))
- {
- string currentUser = user.Key;
- int recievedMessagesCount = recievedMessages[currentUser];
- int sum = recievedMessagesCount + user.Value;
- Console.WriteLine($"{user.Key} - {sum}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment