Advertisement
Guest User

MentorGroup

a guest
Feb 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.67 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. using System.Globalization;
  7.  
  8. namespace MentorGroup
  9. {
  10. class Student
  11. {
  12. public string Name { get; set; }
  13. public List<DateTime> Attendance { get; set; }
  14. public List<string> Comments { get; set; }
  15. }
  16. class Program
  17. {
  18. static void Main(string[] args)
  19. {
  20. var students = new Dictionary<string, Student>();
  21. string input = Console.ReadLine();
  22.  
  23. while (input != "end of dates")
  24. {
  25. string[] nameAndDates = input.Split(' ');
  26. string name = nameAndDates[0];
  27. List<string> dates = new List<string>();
  28. dates = nameAndDates[1].Split(',').ToList();
  29. Student student = new Student();
  30. student.Name = name;
  31. student.Attendance = new List<DateTime>();
  32. student.Comments = new List<string>();
  33. foreach (var data in dates)
  34. {
  35. student.Attendance.Add(DateTime.ParseExact(data, "dd/MM/yyyy", CultureInfo.InvariantCulture));
  36. }
  37. if (students.ContainsKey(name) == false)
  38. {
  39. students.Add(name, student);
  40. }
  41. else
  42. {
  43. students[name].Attendance.AddRange(student.Attendance);
  44. }
  45.  
  46. input = Console.ReadLine();
  47. }
  48.  
  49. input = Console.ReadLine();
  50.  
  51. while (input != "end of comments")
  52. {
  53. var namesAndComments = input.Split('-');
  54. string currentName = namesAndComments[0];
  55. string comment = namesAndComments[1];
  56. if (students.ContainsKey(currentName))
  57. {
  58. students[currentName].Comments.Add(comment);
  59. }
  60. input = Console.ReadLine();
  61. }
  62.  
  63.  
  64. foreach (var student in students.OrderBy(x => x))
  65. {
  66. Console.WriteLine(student.Key);
  67. Console.WriteLine("Comments:");
  68. foreach (var comment in student.Value.Comments)
  69. {
  70. Console.WriteLine($"- {comment}");
  71. }
  72. Console.WriteLine("Dates attended:");
  73. foreach (var date in student.Value.Attendance.OrderBy(x => x))
  74. {
  75. Console.WriteLine($"-- {date.Day}/{date.Month}/{date.Year}");
  76. }
  77. }
  78.  
  79. }
  80.  
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement