Advertisement
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;
- namespace MentorGroup
- {
- class Student
- {
- public string Name { get; set; }
- public List<string> Comment { get; set; }
- public List<DateTime> Attendancy { get; set; }
- }
- class MentorGroup
- {
- static void Main(string[] args)
- {
- var attendanceNameDate = new SortedDictionary<string, List<DateTime>>();
- string commandline = Console.ReadLine();
- while (!commandline.Equals("end of dates"))
- {
- string[] commandArgs = commandline.Split(' ', ',');
- string name = commandArgs[0];
- List<DateTime> dates = new List<DateTime>();
- if (commandArgs.Length > 1)
- {
- for (int i = 1; i < commandArgs.Length; i++)
- {
- DateTime currDate = DateTime.ParseExact(commandArgs[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
- dates.Add(currDate);
- }
- }
- else { }
- var listOfDates = new List<string>();
- for (int i = 1; i < commandArgs.Length; i++)
- {
- listOfDates.Add(commandArgs[i]);
- }
- if (!attendanceNameDate.ContainsKey(name))
- {
- attendanceNameDate.Add(name, new List<DateTime>());
- }
- attendanceNameDate[name].AddRange(dates);
- commandline = Console.ReadLine();
- }
- SortedDictionary<string, List<string>> comments = new SortedDictionary<string, List<string>>();
- string line = Console.ReadLine();
- while (!line.Equals("end of comments"))
- {
- string[] lineArgs = line.Split('-');
- string nameComment = lineArgs[0];
- List<string> comment = new List<string>();
- for (int i = 1; i < lineArgs.Length; i++)
- {
- comment.Add(lineArgs[i]);
- }
- //Check's if line is accurate. If not skip the line.
- if (!attendanceNameDate.ContainsKey(nameComment))
- {
- line = Console.ReadLine();
- continue;
- }
- //Add name, comment to dictionary comments.
- if (!comments.ContainsKey(nameComment))
- {
- comments.Add(nameComment, new List<string>());
- }
- comments[nameComment].AddRange(comment);
- line = Console.ReadLine();
- }
- //List to keep all students name,date and comments.
- List<Student> students = new List<Student>();
- foreach (var person in attendanceNameDate)
- {
- if (comments.ContainsKey(person.Key))
- {
- Student currentStudent = new Student();
- currentStudent.Name = person.Key;
- currentStudent.Attendancy = new List<DateTime>();
- currentStudent.Attendancy.AddRange(person.Value);
- currentStudent.Comment = new List<string>();
- var newList = new List<string>();
- foreach (var item in comments[person.Key])
- {
- newList.Add(item);
- }
- currentStudent.Comment = newList;
- students.Add(currentStudent);
- }
- else
- {
- //return the first element from customers name list that is equal to customerName.
- Student currentStudent = new Student();
- currentStudent.Name = person.Key;
- currentStudent.Attendancy = person.Value;
- currentStudent.Comment = null;
- students.Add(currentStudent);
- }
- }
- foreach (var student in students.OrderBy(c => c.Name))
- {
- Console.WriteLine($"{student.Name}");
- Console.WriteLine("Comments:");
- if (student.Comment == null)
- {
- }
- else
- {
- foreach (var comment in student.Comment)
- {
- if (comment == null) break;
- Console.WriteLine("- {0}", comment);
- }
- }
- Console.WriteLine("Dates attended:");
- foreach (var attend in student.Attendancy.OrderBy(x => x.Date))
- {
- Console.WriteLine("-- {0}", attend.ToString("dd/MM/yyyy"));
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement