Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Globalization;
- namespace Mentor_Group
- {
- class Mentor
- {
- public string Name { get; set; }
- public List<string> comments { get; set; }
- public List<DateTime> dates { get; set; }
- }
- class Program
- {
- static void Main()
- {
- List<Mentor> mentorList = new List<Mentor>();
- string input = Console.ReadLine();
- do
- {
- if (input=="end of dates")
- {
- break;
- }
- string[] inputArr = input
- .Trim()
- .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
- string nameMentor = inputArr[0];
- DateTime date;
- if (!mentorList.Any(x => x.Name == nameMentor))
- {
- Mentor user = new Mentor();
- user.dates = new List<DateTime>();
- user.comments = new List<string>();
- user.Name = nameMentor;
- if (inputArr.Length > 1)
- {
- for (int i = 1; i < inputArr.Length; i++)
- {
- date = DateTime.ParseExact(
- inputArr[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
- user.dates.Add(date);
- }
- }
- mentorList.Add(user);
- }
- else
- {
- if (inputArr.Length > 1)
- {
- for (int i = 1; i < inputArr.Length; i++)
- {
- date = DateTime.ParseExact(
- inputArr[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
- if (!mentorList.Any(x => x.dates.Contains(date)))
- {
- int index = mentorList.FindIndex(x => x.Name == nameMentor);
- mentorList[index].dates.Add(date);
- }
- }
- }
- }
- input = Console.ReadLine();
- } while (input!="end of dates");
- string inputComments = Console.ReadLine();
- do
- {
- if (inputComments=="end of comments")
- {
- break;
- }
- string[] inputCommentsArr = inputComments
- .Trim()
- .Split('-');
- string name = inputCommentsArr[0];
- string comment = inputCommentsArr[1];
- if (mentorList.Any(x => x.Name == name))
- {
- int index = mentorList.FindIndex(x => x.Name == name);
- mentorList[index].comments.Add(comment);
- }
- inputComments = Console.ReadLine();
- } while (inputComments!="end of comments");
- var sortMentorList = mentorList.OrderBy(x => x.Name).ToList();
- foreach (var sml in sortMentorList)
- {
- Console.WriteLine(sml.Name);
- Console.WriteLine("Comments:");
- foreach (var comment in sml.comments)
- {
- Console.WriteLine("- {0}",comment);
- }
- Console.WriteLine("Dates attended:");
- var sortDates = sml.dates.OrderBy(x => x).ToList();
- foreach (var date in sortDates)
- {
- Console.WriteLine("-- {0}",date.ToString("dd/MM/yyyy"));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment