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 OtherCode
- {
- class Program
- {
- static void Main(string[] args)
- {
- SortedDictionary<string, Student> students = new SortedDictionary<string, Student>();
- string input = Console.ReadLine();
- while (input != "end of dates")
- {
- string[] arguments = input.Split().ToArray();
- if (arguments.Length > 1)
- {
- DateTime[] dates = arguments[1].Split(',').Select(e => DateTime.ParseExact(e, "dd/MM/yyyy", CultureInfo.InvariantCulture)).ToArray();
- if (!students.ContainsKey(arguments[0]))
- {
- Student student = new Student(arguments[0]);
- foreach (var date in dates)
- {
- student.AttendanceDate.Add(date);
- }
- students.Add(arguments[0], student);
- }
- else
- {
- foreach (var date in dates)
- {
- students[arguments[0]].AttendanceDate.Add(date);
- }
- }
- }
- else
- {
- if (!students.ContainsKey(arguments[0]))
- {
- students.Add(arguments[0], new Student(arguments[0]));
- }
- }
- input = Console.ReadLine();
- }
- input = Console.ReadLine();
- while (input != "end of comments")
- {
- string[] comments = input.Split('-').ToArray();
- if (students.ContainsKey(comments[0]))
- {
- students[comments[0]].Comments.Add(comments[1]);
- }
- input = Console.ReadLine();
- }
- foreach (var student in students)
- {
- 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.AttendanceDate.OrderBy(x => x))
- {
- Console.WriteLine($"-- {date.ToString("dd/MM/yyyy")}");
- }
- }
- }
- class Student
- {
- public List<string> Comments { get; set; }
- public List<DateTime> AttendanceDate { get; set; }
- public string Name { get; set; }
- public Student(string name)
- {
- this.Comments = new List<string>();
- this.AttendanceDate = new List<DateTime>();
- this.Name = name;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement