tsekotsolov

MentorGroup

Oct 25th, 2017
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. namespace P08_MentorGroup
  7. {
  8.     class P08_MentorGroup
  9.     {
  10.         class Student
  11.         {
  12.             public List<string> Comments { get; set; } = new List<string>();
  13.             public List<DateTime> Dates { get; set; } = new List<DateTime>();
  14.             public string Name { get; set; }
  15.         }
  16.  
  17.         static void Main()
  18.         {
  19.             var inputLineOfDates = Console.ReadLine();
  20.  
  21.             SortedDictionary<string, Student> studentsDict = new SortedDictionary<string, Student>();
  22.  
  23.             while (inputLineOfDates != "end of dates")
  24.             {
  25.  
  26.                 var input = inputLineOfDates.Split(' ', ',');
  27.  
  28.                 var name = input.First();
  29.  
  30.                 var dates = input
  31.                     .Skip(1)
  32.                     .Select(x => DateTime.ParseExact(x, "dd/MM/yyyy", CultureInfo.InvariantCulture))
  33.                     .OrderBy(x => x)
  34.                     .ToList();
  35.  
  36.                 Student currentstudent = new Student()
  37.                 {
  38.                     Name = name,
  39.                     Dates = dates
  40.                 };
  41.                 if (!studentsDict.ContainsKey(name))
  42.  
  43.                 {
  44.                     studentsDict.Add(name, currentstudent);
  45.                 }
  46.  
  47.                 else
  48.                 {
  49.                     studentsDict[name].Dates.AddRange(currentstudent.Dates);
  50.                 }
  51.  
  52.                 inputLineOfDates = Console.ReadLine();
  53.             }
  54.  
  55.             var inputLineOfComments = Console.ReadLine();
  56.  
  57.             while (inputLineOfComments != "end of comments")
  58.             {
  59.                 var input = inputLineOfComments.Split('-');
  60.  
  61.                 var name = input.First();
  62.  
  63.                 var comments = input
  64.                     .Skip(1)
  65.                     .OrderBy(x => x)
  66.                     .ToList();
  67.  
  68.                 if (studentsDict.ContainsKey(name))
  69.  
  70.                 {
  71.                     Student currentstudent = new Student()
  72.                     {
  73.                         Name = name,
  74.                         Comments = comments
  75.                     };
  76.                     studentsDict[name].Comments.AddRange(currentstudent.Comments);
  77.                 }
  78.  
  79.                 inputLineOfComments = Console.ReadLine();
  80.             }
  81.  
  82.             foreach (var student in studentsDict)
  83.             {
  84.                 Console.WriteLine(student.Key);
  85.  
  86.                 Console.WriteLine("Comments:");
  87.                 foreach (var item in student.Value.Comments)
  88.                 {
  89.  
  90.                     Console.WriteLine($"- {item}");
  91.                 }
  92.  
  93.                 Console.WriteLine("Dates attended:");
  94.                 foreach (var item in student.Value.Dates)
  95.                 {
  96.  
  97.                     Console.WriteLine($"-- {item:dd/MM/yyyy}");
  98.                 }
  99.  
  100.             }
  101.  
  102.         }
  103.  
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment