sivancheva

RoliTheCoder3

Oct 31st, 2017
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _04_RoliTheCoder3
  8. {
  9. class RoliTheCoder3
  10. {
  11. static void Main(string[] args)
  12. {
  13. var input = Console.ReadLine();
  14. var result = new Dictionary<string, Dictionary<string, List<string>>>();
  15. while (true)
  16. {
  17. if (input == "Time for Code")
  18. {
  19. break;
  20. }
  21.  
  22. var inputArr = input.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  23. .Select(x => x.Trim()).ToArray();
  24.  
  25.  
  26.  
  27. if (inputArr.Length < 2 || inputArr[1][0] != '#')
  28. {
  29. input = Console.ReadLine();
  30. continue;
  31. }
  32. string id = inputArr[0];
  33. string eventName = inputArr[1];
  34.  
  35. if (!result.ContainsKey(id))
  36. {
  37. result.Add(id, new Dictionary<string, List<string>>());
  38. result[id].Add(eventName, new List<string>());
  39. }
  40. if (inputArr.Length == 2)
  41. {
  42. input = Console.ReadLine();
  43. continue;
  44. }
  45. var participantsList = inputArr.Skip(2).Where(x => x.StartsWith("@")).ToList();
  46. List<string> participants = new List<string>(participantsList);
  47. if (result.ContainsKey(id) && result[id].ContainsKey(eventName))
  48. {
  49. result[id][eventName].AddRange(participants);
  50. }
  51. else if(!result[id].Values.Equals(eventName))
  52. {
  53. input = Console.ReadLine();
  54. continue;
  55. }
  56. else
  57. {
  58. result[id].Add(eventName, new List<string>());
  59. result[id][eventName].AddRange(participants);
  60. }
  61. input = Console.ReadLine();
  62. }
  63.  
  64.  
  65. var sortedDict = result.OrderBy(x => x.Value.First().Key).ToDictionary(x => x.Key, x => x.Value); // тук трябва да са подредени по брой участници (бр елементи в лист)
  66.  
  67. foreach (var item in sortedDict.Values)
  68. {
  69.  
  70. Console.WriteLine($"{item.First().Key} - {item.Values.Count()}");
  71.  
  72. foreach (var participant in item.Values.OrderByDescending(x=>x))
  73. {
  74.  
  75. Console.WriteLine($"{participant}");
  76. }
  77. }
  78.  
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment