Advertisement
Guest User

Untitled

a guest
Feb 10th, 2017
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.97 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 Student
  9. {
  10. public string Name { get; set; }
  11.  
  12. public List<string> Comment { get; set; }
  13.  
  14. public List<DateTime> Attendancy { get; set; }
  15. }
  16. class MentorGroup
  17. {
  18. static void Main(string[] args)
  19. {
  20. var attendanceNameDate = new SortedDictionary<string, List<DateTime>>();
  21.  
  22. string commandline = Console.ReadLine();
  23. while (!commandline.Equals("end of dates"))
  24. {
  25. string[] commandArgs = commandline.Split(' ', ',');
  26. string name = commandArgs[0];
  27.  
  28.  
  29. List<DateTime> dates = new List<DateTime>();
  30. if (commandArgs.Length > 1)
  31. {
  32.  
  33. for (int i = 1; i < commandArgs.Length; i++)
  34. {
  35. DateTime currDate = DateTime.ParseExact(commandArgs[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  36. dates.Add(currDate);
  37. }
  38. }
  39. else { }
  40.  
  41. var listOfDates = new List<string>();
  42. for (int i = 1; i < commandArgs.Length; i++)
  43. {
  44. listOfDates.Add(commandArgs[i]);
  45. }
  46. if (!attendanceNameDate.ContainsKey(name))
  47. {
  48. attendanceNameDate.Add(name, new List<DateTime>());
  49. }
  50.  
  51. attendanceNameDate[name].AddRange(dates);
  52.  
  53. commandline = Console.ReadLine();
  54. }
  55.  
  56. SortedDictionary<string, List<string>> comments = new SortedDictionary<string, List<string>>();
  57.  
  58. string line = Console.ReadLine();
  59. while (!line.Equals("end of comments"))
  60. {
  61. string[] lineArgs = line.Split('-');
  62. string nameComment = lineArgs[0];
  63. List<string> comment = new List<string>();
  64.  
  65. for (int i = 1; i < lineArgs.Length; i++)
  66. {
  67. comment.Add(lineArgs[i]);
  68. }
  69.  
  70. //Check's if line is accurate. If not skip the line.
  71. if (!attendanceNameDate.ContainsKey(nameComment))
  72. {
  73. line = Console.ReadLine();
  74. continue;
  75. }
  76.  
  77. //Add name, comment to dictionary comments.
  78. if (!comments.ContainsKey(nameComment))
  79. {
  80. comments.Add(nameComment, new List<string>());
  81. }
  82. comments[nameComment].AddRange(comment);
  83.  
  84.  
  85. line = Console.ReadLine();
  86. }
  87.  
  88. //List to keep all students name,date and comments.
  89. List<Student> students = new List<Student>();
  90.  
  91. foreach (var person in attendanceNameDate)
  92. {
  93. if (comments.ContainsKey(person.Key))
  94. {
  95. Student currentStudent = new Student();
  96. currentStudent.Name = person.Key;
  97. currentStudent.Attendancy = new List<DateTime>();
  98. currentStudent.Attendancy.AddRange(person.Value);
  99. currentStudent.Comment = new List<string>();
  100.  
  101. var newList = new List<string>();
  102. foreach (var item in comments[person.Key])
  103. {
  104. newList.Add(item);
  105. }
  106.  
  107. currentStudent.Comment = newList;
  108.  
  109. students.Add(currentStudent);
  110. }
  111. else
  112. {
  113. //return the first element from customers name list that is equal to customerName.
  114. Student currentStudent = new Student();
  115. currentStudent.Name = person.Key;
  116. currentStudent.Attendancy = person.Value;
  117. currentStudent.Comment = null;
  118. students.Add(currentStudent);
  119. }
  120. }
  121.  
  122. foreach (var student in students.OrderBy(c => c.Name))
  123. {
  124. Console.WriteLine($"{student.Name}");
  125.  
  126. Console.WriteLine("Comments:");
  127. if (student.Comment == null)
  128. {
  129.  
  130. }
  131. else
  132. {
  133. foreach (var comment in student.Comment)
  134. {
  135. if (comment == null) break;
  136. Console.WriteLine("- {0}", comment);
  137. }
  138. }
  139.  
  140. Console.WriteLine("Dates attended:");
  141. foreach (var attend in student.Attendancy.OrderBy(x => x.Date))
  142. {
  143. Console.WriteLine("-- {0}", attend.ToString("dd/MM/yyyy"));
  144. }
  145.  
  146. }
  147.  
  148. }
  149. }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement