Advertisement
Guest User

08.Mentor Group

a guest
Oct 19th, 2017
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.57 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 _08.MentorGroup
  9. {
  10.     class Student
  11.     {
  12.         public List<string> Comments { get; set; }
  13.         public List<DateTime> DatesAttended { get; set; }
  14.     }
  15.     class MentorGroup
  16.     {
  17.         static void Main()
  18.         {
  19.             SortedDictionary<string, Student> studentsData = new SortedDictionary<string, Student>();
  20.  
  21.             string firstInput = Console.ReadLine();
  22.  
  23.             while (firstInput != "end of dates")
  24.             {
  25.                 List<DateTime> datesAttended = new List<DateTime>();
  26.  
  27.                 string[] tokens = firstInput.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  28.  
  29.                 string userName = tokens[0];
  30.  
  31.                 if (tokens.Length > 1)
  32.                 {
  33.                     string[] dates = tokens[1].Split(',');
  34.  
  35.                     for (int i = 0; i < dates.Length; i++)
  36.                     {
  37.                         DateTime currentDate = DateTime.ParseExact(dates[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  38.  
  39.                         datesAttended.Add(currentDate);
  40.                     }
  41.  
  42.                     Student student = new Student();
  43.  
  44.                     if (!studentsData.ContainsKey(userName))
  45.                     {
  46.                         studentsData.Add(userName, student);
  47.                         student.DatesAttended = datesAttended;
  48.                         student.Comments = new List<string>();
  49.                     }
  50.                     else
  51.                     {
  52.                         studentsData[userName].DatesAttended.AddRange(datesAttended);
  53.                     }
  54.                 }
  55.  
  56.                 firstInput = Console.ReadLine();
  57.             }
  58.  
  59.             string secondInput = Console.ReadLine();
  60.  
  61.             while (secondInput != "end of comments")
  62.             {
  63.                 List<string> comments = new List<string>();
  64.  
  65.                 string[] tokens = secondInput.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  66.  
  67.                 string userName = tokens[0];
  68.                 string comment = tokens[1];
  69.  
  70.                 comments.Add(comment);
  71.  
  72.                 if (studentsData.ContainsKey(userName))
  73.                 {
  74.                     if (studentsData[userName].Comments.Count > 0)
  75.                     {
  76.                         studentsData[userName].Comments.AddRange(comments);
  77.                     }
  78.                     else
  79.                     {
  80.                         studentsData[userName].Comments = comments;
  81.                     }
  82.                 }
  83.  
  84.                 secondInput = Console.ReadLine();
  85.             }
  86.  
  87.             foreach (KeyValuePair<string, Student> students in studentsData)
  88.             {
  89.                 string userName = students.Key;
  90.                 Student student = students.Value;
  91.  
  92.                 List<DateTime> datesAttended = student.DatesAttended;
  93.                 List<string> comments = student.Comments;
  94.  
  95.                 Console.WriteLine(userName);
  96.                 Console.WriteLine("Comments:");
  97.  
  98.                 foreach (string comment in comments)
  99.                 {
  100.                     Console.WriteLine($"- {comment}");
  101.                 }
  102.  
  103.                 Console.WriteLine("Dates attended:");
  104.  
  105.                 foreach (DateTime date in datesAttended.OrderBy(d => d))
  106.                 {
  107.                     Console.WriteLine($"-- {date.ToString("dd/MM/yyyy")}");
  108.                 }
  109.             }
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement