Advertisement
YavorJS

Mentor group

Oct 16th, 2016
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. class Program
  9. {
  10. static void Main()
  11. {
  12. SortedDictionary<string, List<DateTime>> userNames = new SortedDictionary<string, List<DateTime>>();
  13. Dictionary<string, List<string>> userComments = new Dictionary<string, List<string>>();
  14. string command = "";
  15. while (command != "end")
  16. {
  17. string[] input = Console.ReadLine().Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  18. string name = input[0];
  19. if (name == "end") break;
  20. List<DateTime> dates = input.Skip(1).Select(date => DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture)).ToList();
  21. if (!userNames.ContainsKey(name)) userNames.Add(name, new List<DateTime>());
  22. userNames[name].AddRange(dates);
  23. }
  24. command = "";
  25. while (command != "end of comments")
  26. {
  27. string[] input = Console.ReadLine().Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  28. string name = input[0];
  29. if (name == "end of comments") break;
  30. string comment = input[1];
  31. List<string> comments = new List<string>();
  32. comments.Add(comment);
  33. if (userNames.ContainsKey(name) && !userComments.ContainsKey(name)) userComments.Add(name, new List<string>());
  34. if (userComments.ContainsKey(name)) userComments[name].AddRange(comments);
  35. }
  36. foreach (var user in userNames)
  37. {
  38. string person = user.Key;
  39. Console.WriteLine(person);
  40. Console.WriteLine("Comments:");
  41. foreach (var human in userComments)
  42. {
  43. List<string> comments = human.Value;
  44. string man = human.Key;
  45. if (man == person)
  46. {
  47. Console.WriteLine("- " + string.Join("\r\n- ", comments));
  48. }
  49. }
  50. List<DateTime> dates = user.Value;
  51. Console.WriteLine("Dates attended:");
  52. foreach (var date in dates.OrderBy(x => x))
  53. {
  54. string ourDate = date.ToString("dd/MM/yyyy");
  55. Console.WriteLine("-- " + ourDate);
  56. }
  57. }
  58.  
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement