Advertisement
silvana1303

message manager

Aug 2nd, 2020
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4. using System.Text;
  5. using System.Linq;
  6. using System.Windows.Markup;
  7. using System.IO;
  8. using System.Data;
  9.  
  10. namespace _01._Furniture
  11. {
  12.     class Program
  13.     {
  14.         static void Main(string[] args)
  15.         {
  16.             int capacity = int.Parse(Console.ReadLine());
  17.             string[] command = Console.ReadLine().Split('=');
  18.  
  19.             var sent = new Dictionary<string, int>();
  20.             var received = new Dictionary<string, int>();
  21.             var messages = new Dictionary<string, int>();
  22.  
  23.             while (command[0] != "Statistics")
  24.             {
  25.                 if (command[0] == "Add")
  26.                 {
  27.                     if ((!sent.ContainsKey(command[1])) && !received.ContainsKey(command[1]))
  28.                     {
  29.                         sent[command[1]] = int.Parse(command[2]);
  30.                         received[command[1]] = int.Parse(command[3]);
  31.                         messages[command[1]] = sent[command[1]] + received[command[1]];
  32.                     }
  33.                 }
  34.                 if (command[0] == "Message")
  35.                 {
  36.                     //•   "Message={sender}={receiver}":
  37.                     if (sent.ContainsKey(command[1]) && received.ContainsKey(command[2]))
  38.                     {
  39.                         sent[command[1]]++;
  40.                         received[command[2]]++;
  41.                         messages[command[1]]++;
  42.                         messages[command[2]]++;
  43.  
  44.                         if (messages[command[1]] >= capacity)
  45.                         {
  46.                             sent.Remove(command[1]);
  47.                             received.Remove(command[1]);
  48.                             messages.Remove(command[1]);
  49.                             Console.WriteLine($"{command[1]} reached the capacity!");
  50.                         }
  51.                         if (messages[command[2]] >= capacity)
  52.                         {
  53.                             sent.Remove(command[2]);
  54.                             received.Remove(command[2]);
  55.                             messages.Remove(command[2]);
  56.                             Console.WriteLine($"{command[2]} reached the capacity!");
  57.                         }
  58.                         // if (sent[command[1]] == capacity)
  59.                         // {
  60.                         //     sent.Remove(command[1]);
  61.                         //    received.Remove(command[1]);
  62.                         //    Console.WriteLine($"{command[1]} reached the capacity!");
  63.                         //  }
  64.                         //  if (received[command[2]] == capacity)
  65.                         // {
  66.                         //     sent.Remove(command[2]);
  67.                         //     received.Remove(command[2]);
  68.                         //      Console.WriteLine($"{command[2]} reached the capacity!");
  69.                         //  }
  70.  
  71.                     }
  72.                 }
  73.                 if (command[0] == "Empty")
  74.                 {
  75.                     if (sent.ContainsKey(command[1]))
  76.                     {
  77.                         sent.Remove(command[1]);
  78.                         received.Remove(command[1]);
  79.                     }
  80.  
  81.                     if (command[1] == "All")
  82.                     {
  83.                         sent.Clear();
  84.                         received.Clear();
  85.                     }
  86.                 }
  87.  
  88.                 command = Console.ReadLine().Split('=');
  89.             }
  90.  
  91.             Console.WriteLine($"Users count: {sent.Count}");
  92.  
  93.             foreach (var item in received.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
  94.             {
  95.                 //{username} - {messages}
  96.                 Console.WriteLine($"{item.Key} - {messages[item.Key]}");
  97.             }
  98.         }
  99.     }
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement