whitestarrr

Untitled

Oct 22nd, 2016
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace MentorGroup
  7. {
  8. class User
  9. {
  10. public string Name { get; set; }
  11. public List<string> Comments { get; set; }
  12. public List<DateTime> Dates { get; set; }
  13. }
  14. class Program
  15. {
  16. static void Main(string[] args)
  17. {
  18. var dateInput = Console.ReadLine();
  19. List<User> users = new List<User>();
  20. while (!dateInput.Equals("end of dates"))
  21. {
  22. var split = dateInput.Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  23. if (users.Any(x => x.Name == split[0]))
  24. {
  25. List<DateTime> dates = new List<DateTime>();
  26. for (int i = 1; i < split.Length; i++)
  27. {
  28. dates.Add(DateTime.ParseExact(split[i], "dd/MM/yyyy", CultureInfo.InvariantCulture));
  29. }
  30. var existingUser = users.First(c => c.Name == split[0]);
  31. existingUser.Dates.AddRange(dates);
  32. }
  33. else
  34. {
  35. List<DateTime> dates = new List<DateTime>();
  36. List<string> comments = new List<string>();
  37. User user = new User();
  38. user.Name = split[0];
  39. for (int i = 1; i < split.Length; i++)
  40. {
  41. dates.Add(DateTime.ParseExact(split[i], "dd/MM/yyyy", CultureInfo.InvariantCulture).Date);
  42. }
  43. user.Dates = dates;
  44. user.Comments = comments;
  45. users.Add(user);
  46. }
  47.  
  48. dateInput = Console.ReadLine();
  49. }
  50. var commentssInput = Console.ReadLine();
  51. while (!commentssInput.Equals("end of comments"))
  52. {
  53. var split = commentssInput.Split('-').ToArray();
  54. if (users.Any(x => x.Name == split[0]))
  55. {
  56. List<string> comments = new List<string>();
  57. string userName = split[0];
  58. for (int i = 1; i < split.Length; i++)
  59. {
  60. comments.Add(split[i]);
  61. }
  62. users.First(x => x.Name == userName).Comments.AddRange(comments);
  63. }
  64. commentssInput = Console.ReadLine();
  65. }
  66. var ordered = users.OrderBy(x => x.Name).ThenByDescending(x => x.Dates);
  67. foreach (var user in ordered)
  68. {
  69. Console.WriteLine(user.Name);
  70. Console.WriteLine("Comments:");
  71. foreach (var comment in user.Comments)
  72. {
  73. Console.WriteLine("- {0}", comment);
  74. }
  75. Console.WriteLine("Dates attended:");
  76. foreach (var date in user.Dates.OrderBy(x => x.Date))
  77. {
  78. Console.WriteLine("-- {0}", date.ToString("dd/MM/yyyy"));
  79. }
  80. }
  81. }
  82.  
  83. }
  84.  
  85. }
Add Comment
Please, Sign In to add comment