Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- sing System;
- using System.Collections.Generic;
- using System.Linq;
- namespace MessagesManager2
- {
- public class Info
- {
- public int send { get; set; }
- public int received { get; set; }
- }
- internal class Program
- {
- private static void Main(string[] args)
- {
- Dictionary<string, Info> pairs = new Dictionary<string, Info>();
- int maxCapacity = int.Parse(Console.ReadLine());
- string input = Console.ReadLine();
- while (input != "Statistics")
- {
- string[] array = input.Split('=');
- string action = array[0];
- if (action.Equals("Add", StringComparison.InvariantCulture))
- {
- string username = array[1];
- int sent = int.Parse(array[2]);
- int received = int.Parse(array[3]);
- if (!pairs.ContainsKey(username))
- {
- pairs.Add(username, new Info());
- pairs[username].send = sent;
- pairs[username].received = received;
- }
- }
- else if (action.Equals("Empty", StringComparison.InvariantCulture))
- {
- string userName = array[1];
- if (userName.Equals("All", StringComparison.InvariantCulture))
- {
- pairs.Clear();
- }
- else if (pairs.ContainsKey(userName))
- {
- pairs.Remove(userName);
- }
- }
- else if (action.Equals("Message", StringComparison.InvariantCulture))
- {
- string sender = array[1];
- string receiver = array[2];
- if (pairs.ContainsKey(sender) && pairs.ContainsKey(receiver))
- {
- pairs[sender].send += 1;
- pairs[receiver].received += 1;
- if (pairs[sender].send + pairs[sender].received >= maxCapacity)
- {
- Console.WriteLine("{0} reached the capacity!", sender);
- pairs.Remove(sender);
- }
- if (pairs[receiver].send + pairs[receiver].received >= maxCapacity)
- {
- Console.WriteLine("{0} reached the capacity!", receiver);
- pairs.Remove(receiver);
- }
- }
- }
- input = Console.ReadLine();
- }
- Console.WriteLine($"Users count: {pairs.Count}");
- foreach (KeyValuePair<string, Info> kvp in pairs.OrderByDescending(p => p.Value.received).ThenBy(p => p.Key))
- {
- Console.WriteLine($"{kvp.Key} - {kvp.Value.received + kvp.Value.send}");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment