TonyTroev

Mentor Group

Feb 28th, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.38 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace _08_MentorGroup
  7. {
  8.     class MentorGroup
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, Mentor> mentors = new Dictionary<string, Mentor>();
  13.  
  14.             while (true)
  15.             {
  16.                 string[] input = Console.ReadLine()
  17.                 .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  18.                 if (input[0] == "end" && input[1] == "of" && input[2] == "dates")
  19.                 {
  20.                     break;
  21.                 }
  22.  
  23.                 string name = input[0];
  24.                 if (!mentors.ContainsKey(name))
  25.                 {
  26.                     mentors.Add(name, new Mentor());
  27.                 }
  28.  
  29.                 for (int i = 1; i < input.Length; i++)
  30.                 {
  31.                     mentors[name].Attendances.Add(DateTime.ParseExact(input[i], "dd/MM/yyyy", DateTimeFormatInfo.InvariantInfo));
  32.                 }
  33.             }
  34.  
  35.             while (true)
  36.             {
  37.                 string[] input = Console.ReadLine()
  38.                 .Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  39.                 if (input[0] == "end of comments")
  40.                 {
  41.                     break;
  42.                 }
  43.  
  44.                 string name = input[0];
  45.                 if (mentors.ContainsKey(name))
  46.                 {
  47.                     mentors[name].Comments.Add(input[1]);
  48.                 }
  49.             }
  50.  
  51.             foreach (var mentor in mentors.OrderBy(x => x.Key))
  52.             {
  53.                 Console.WriteLine(mentor.Key);
  54.                 Console.WriteLine("Comments:");
  55.                 foreach (string comment in mentor.Value.Comments)
  56.                 {
  57.                     Console.WriteLine($"- {comment}");
  58.                 }
  59.                 Console.WriteLine("Dates attended:");
  60.                 foreach (DateTime date in mentor.Value.Attendances.OrderBy(x => x))
  61.                 {
  62.                     Console.WriteLine($"-- {date:dd/MM/yyyy}");
  63.                 }
  64.             }
  65.         }
  66.     }
  67.  
  68.     class Mentor
  69.     {
  70.         public List<string> Comments;
  71.         public List<DateTime> Attendances;
  72.  
  73.         public Mentor()
  74.         {
  75.             Comments = new List<string>();
  76.             Attendances = new List<DateTime>();
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment