Advertisement
Guest User

08. Mentor Group

a guest
Feb 13th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. class MentorGroup
  7. {
  8.     static void Main()
  9.     {
  10.         var result = new List<User>();
  11.  
  12.         while(true)
  13.         {
  14.             string[] inputLine = Console.ReadLine().Split(' ').Where(a => a.Length > 0).ToArray();
  15.             if (inputLine[0] == "end")
  16.                 break;
  17.             string username = inputLine[0];
  18.             if (inputLine.Length > 1)
  19.             {              
  20.                 List<DateTime> dates = inputLine[1]
  21.                     .Split(',')
  22.                     .Where(a => a.Length > 0)
  23.                     .Select(a => DateTime.ParseExact(a, "dd/MM/yyyy", CultureInfo.InvariantCulture))
  24.                     .ToList();
  25.                 if (result.Where(u => u.Name == username).Count() > 0)
  26.                 {
  27.                     User userFromList = result.Where(u => u.Name == username).First();
  28.                     userFromList.Dates.AddRange(dates);
  29.                 }
  30.                 else
  31.                 {
  32.                     User userToAdd = new User() { Name = username, Dates = new List<DateTime>() , Comments = new List<string>()};
  33.                     userToAdd.Dates.AddRange(dates);
  34.                     result.Add(userToAdd);
  35.                 }
  36.             }
  37.             else
  38.             {
  39.                 result.Add(new User() { Name = username , Comments = new List<string>(), Dates = new List<DateTime>()});
  40.             }
  41.         }
  42.  
  43.         while(true)
  44.         {
  45.             string[] inputLine = Console.ReadLine().Split('-').Where(a => a.Length > 0).ToArray();
  46.             if (inputLine[0] == "end of comments")
  47.                 break;
  48.             string username = inputLine[0];
  49.             if (result.Where(u => u.Name == username).Count() > 0 && inputLine.Length > 1)
  50.             {
  51.                 User userFromList = result.Where(u => u.Name == username).First();
  52.                 userFromList.Comments.Add(inputLine[1]);
  53.             }
  54.         }
  55.  
  56.         foreach (User user in result.OrderBy(u => u.Name))
  57.         {
  58.             Console.WriteLine($"{user.Name}");
  59.             Console.WriteLine($"Comments:");
  60.             foreach (string comment in user.Comments)
  61.             {
  62.                 Console.WriteLine($"- {comment}");
  63.             }
  64.             Console.WriteLine($"Dates attended:");
  65.             foreach (DateTime date in user.Dates.OrderBy(u => u.Date))
  66.             {
  67.                 Console.WriteLine($"-- {date:dd/MM/yyyy}");
  68.             }
  69.         }
  70.     }
  71. }
  72. class User
  73. {
  74.     public string Name { get; set; }
  75.  
  76.     public List<DateTime> Dates { get; set; }
  77.  
  78.     public List<string> Comments { get; set; }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement