Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _24_08_MentorGroup
- {
- class MentorGroup
- {
- static void Main(string[] args)
- {
- var input = Console.ReadLine();
- var result = new Dictionary<string, Student>();
- while (input != "end of dates")
- {
- var inputNameDates = input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
- string name = inputNameDates[0];
- List<DateTime> datesToAdd = new List<DateTime>();
- if (inputNameDates.Length > 1)
- {
- for (int i = 1; i < inputNameDates.Length; i++)
- {
- DateTime date = DateTime.ParseExact(inputNameDates[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
- datesToAdd.Add(date);
- }
- }
- Student studentToAdd = new Student();
- studentToAdd.Dates = new List<DateTime>();
- studentToAdd.Comments = new List<string>();
- studentToAdd.Dates.AddRange(datesToAdd);
- if (!result.ContainsKey(name))
- {
- result.Add(name, new Student());
- result[name] = studentToAdd;
- }
- else if (result.ContainsKey(name))
- {
- result[name].Dates.AddRange(datesToAdd);
- }
- input = Console.ReadLine();
- }
- input = Console.ReadLine();
- while (input != "end of comments")
- {
- var inputNameComments = input.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries).Select(x => x.Trim()).ToArray();
- string name = inputNameComments[0];
- List<string> commentsToAdd = new List<string>();
- if (inputNameComments.Length > 1)
- {
- for (int i = 1; i < inputNameComments.Length; i++)
- {
- commentsToAdd.Add(inputNameComments[i]);
- }
- }
- if (result.ContainsKey(name))
- {
- result[name].Comments.AddRange(commentsToAdd);
- }
- input = Console.ReadLine();
- }
- foreach (var student in result.OrderBy(x => x.Key))
- {
- Console.WriteLine($"{student.Key}");
- Console.WriteLine($"Comments:");
- foreach (var comment in student.Value.Comments)
- {
- Console.WriteLine($"- {comment}");
- }
- Console.WriteLine("Dates attended:");
- foreach (var date in student.Value.Dates.OrderBy(x => x))
- {
- Console.WriteLine($"-- {date:dd/MM/yyyy}");
- }
- }
- }
- }
- class Student
- {
- public List<string> Comments { get; set; }
- public List<DateTime> Dates { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment