Advertisement
Guest User

Untitled

a guest
Feb 25th, 2018
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 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. namespace _08.RealProgram
  9. {
  10. class Program
  11. {
  12. class Student
  13. {
  14. public string Name { get; set; }
  15. public List<DateTime> Dates { get; set; }
  16. public List<string> Comments { get; set; }
  17. }
  18. static void Main(string[] args)
  19. {
  20. List<Student> studentNameAndDates = ReadStudentInfo();
  21. List<Student> studnetNameAndComments = ReadComments(studentNameAndDates);
  22. PrintResult(studnetNameAndComments);
  23. }
  24.  
  25. static void PrintResult(List<Student> studnetNameAndComments)
  26. {
  27. foreach (var name in studnetNameAndComments.OrderBy(a => a.Name))
  28. {
  29. Console.WriteLine($"{name.Name}");
  30. Console.WriteLine("Comments:");
  31. foreach (var comment in name.Comments)
  32. {
  33. Console.WriteLine($"- {comment}");
  34. }
  35. Console.WriteLine("Dates attended:");
  36. foreach (var date in name.Dates.OrderBy(a => a))
  37. {
  38. Console.WriteLine($"-- {date:dd/MM/yyyy}");
  39. }
  40. }
  41. }
  42.  
  43. static List<Student> ReadComments(List<Student> studentNameAndDates)
  44. {
  45. while (true)
  46. {
  47. var nameAndComment = Console.ReadLine().Split('-').ToList();
  48. if (nameAndComment[0] == "end of comments" || nameAndComment[0] == "end of dates")
  49. {
  50. return studentNameAndDates;
  51. }
  52. var name = nameAndComment[0];
  53. var comment = nameAndComment[1];
  54. if (studentNameAndDates.Any(a => a.Name == name))
  55. {
  56. Student abv = studentNameAndDates.First(a => a.Name == name);
  57. abv.Comments.Add(comment);
  58. }
  59. }
  60. }
  61.  
  62. static List<Student> ReadStudentInfo()
  63. {
  64. List<Student> nameDate = new List<Student>();
  65. while (true)
  66. {
  67. var nameAndDate = Console.ReadLine().Split(' ', ',').ToList();
  68. if (nameAndDate[0] == "end")
  69. {
  70. return nameDate;
  71. }
  72. var date = nameAndDate.Skip(1).ToList();
  73. var name = nameAndDate[0];
  74. var info = new Student();
  75. info.Dates = new List<DateTime>() ;
  76. if (nameDate.Any(a => a.Name == name))
  77. {
  78. for (int i = 0; i < date.Count; i++)
  79. {
  80. info.Dates.Add(DateTime.ParseExact(date[i], "dd/MM/yyyy", CultureInfo.InvariantCulture));
  81.  
  82. }
  83.  
  84. }
  85. else
  86. {
  87. info.Name = name;
  88. for (int i = 0; i < date.Count; i++)
  89. {
  90. info.Dates.Add(DateTime.ParseExact(date[i], "dd/MM/yyyy", CultureInfo.InvariantCulture));
  91. }
  92.  
  93. info.Comments = new List<string>();
  94. nameDate.Add(info);
  95. }
  96. }
  97. }
  98. }
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement