Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Globalization;
- namespace MentorGroup
- {
- public class Student
- {
- public string Name { get; set; }
- public List<DateTime> Date { get; set; }
- public List<string> Comments { get; set; }
- }
- class MainClass
- {
- public static void Main(string[] args)
- {
- List<Student> studentList = new List<Student>();
- List<DateTime> dates = new List<DateTime>();
- Student student = new Student();
- string input = Console.ReadLine();
- while (input != "end of dates")
- {
- var line = input.Split(new char[] { ' ' },
- StringSplitOptions
- .RemoveEmptyEntries);
- string name = line[0];
- student.Name = name;
- if (line.Length > 1)
- {
- var dateString = line[1].Split(',').ToList();
- foreach (var item in dateString)
- {
- dates.Add(DateTime.ParseExact(item, "dd/MM/yyyy",
- CultureInfo
- .InvariantCulture));
- }
- student.Date = dates;
- }
- studentList.Add(student);
- dates = new List<DateTime>();
- student = new Student();
- input = Console.ReadLine();
- }
- string comments = Console.ReadLine();
- while (comments != "end of comments")
- {
- var arguments = comments.Split('-');
- var commentName = arguments[0];
- var commentNew = arguments[1];
- foreach (var s in studentList)
- {
- if (s.Name == commentName)
- {
- if (s.Comments == null)
- {
- s.Comments = new List<string>();
- s.Comments.Add(commentNew);
- }
- else
- {
- s.Comments.Add(commentNew);
- }
- }
- }
- comments = Console.ReadLine();
- }
- List<Student> sorted = studentList.OrderBy(x => x.Name)
- .ThenBy(x => x.Date).ToList();
- foreach (var s in sorted)
- {
- Console.WriteLine(s.Name);
- Console.WriteLine("Comments:");
- List<string> commentsList = s.Comments;
- if (commentsList != null)
- {
- Console.WriteLine($"- {string.Join("",s.Comments)}");
- }
- Console.WriteLine("Dates attended:");
- if (s.Date != null)
- {
- List<DateTime> date = s.Date.OrderBy(d => d.Date).ToList();
- if (date != null)
- {
- foreach (var d in date)
- {
- Console.WriteLine("-- " + d.ToString("dd/MM/yyyy"));
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement