Advertisement
Guest User

Untitled

a guest
Jan 9th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8.  
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var students=GetStudentsInfo();
  14. PrintStudentsDatesAndComments(students);
  15.  
  16. }
  17.  
  18. static void PrintStudentsDatesAndComments(Dictionary<string, Student> students)
  19. {
  20. foreach (var student in students)
  21. {
  22. Console.WriteLine(student.Key);
  23. Console.WriteLine("Comments:");
  24.  
  25. foreach (var comment in student.Value.Comments)
  26. {
  27. Console.WriteLine($"- {comment}");
  28. }
  29. Console.WriteLine("Dates attended:");
  30.  
  31. foreach (var date in student.Value.AppendDates.OrderBy(x=>x))
  32. {
  33. Console.WriteLine($"-- {date:dd/MM/yyyy}");
  34. }
  35. }
  36. }
  37.  
  38. static Dictionary<string, Student> GetStudentsInfo()
  39. {
  40.  
  41. Dictionary<string, Student> students = GetNameAndDates();
  42. students = GetCommentsForStudents(students);
  43. return students.OrderBy(n=> n.Key).ToDictionary(k=>k.Key,v=>v.Value);
  44.  
  45. }
  46.  
  47. static Dictionary<string, Student> GetCommentsForStudents(Dictionary<string, Student> students)
  48. {
  49.  
  50. string input = Console.ReadLine();
  51. while (input!="end of comments")
  52. {
  53. var currentInput = input.Split('-').ToList();
  54. var studentName = currentInput.First();
  55. var currentComment = currentInput.Skip(1).First();
  56. if (students.ContainsKey(studentName))
  57. {
  58. students[studentName].Comments.Add(currentComment);
  59. }
  60. input = Console.ReadLine();
  61. }
  62. return students;
  63. }
  64.  
  65. static Dictionary<string, Student> GetNameAndDates()
  66. {
  67. var students = new Dictionary<string, Student>();
  68. string input = Console.ReadLine();
  69. while (input != "end of dates")
  70. {
  71. var currentInput = input.Split().ToList();
  72. var studentName = currentInput.First();
  73. if (!students.ContainsKey(studentName))
  74. {
  75. students[studentName] = new Student
  76. {
  77. StudentName = studentName,
  78. AppendDates = new List<DateTime>()
  79. };
  80. }
  81. if (currentInput.Count > 1)
  82. {
  83. var listOfDates = currentInput[1].Split(',').ToList();
  84. for (int i = 0; i < listOfDates.Count; i++)
  85. {
  86. var currentDate = DateTime.ParseExact(listOfDates[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  87. students[studentName].AppendDates.Add(currentDate);
  88. }
  89.  
  90. }
  91. input = Console.ReadLine();
  92. }
  93. return students;
  94. }
  95. }
  96. class Student
  97. {
  98. public string StudentName { get; set; }
  99.  
  100. public List<DateTime> AppendDates = new List<DateTime>();
  101.  
  102. public List<string> Comments = new List<string>();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement