Advertisement
Guest User

08.Mentor Group

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