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