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;
- public class Soft
- {
- public static void Main()
- {
- SortedDictionary<string,Student> group = new SortedDictionary<string,Student>();
- List<string> input = Console.ReadLine().Split(new char[] { ' ',','}).ToList();
- while(input[0]!="end")
- {
- if (input.Count == 1)
- {
- input = Console.ReadLine().Split(new char[] { ' ', ',' }).ToList();
- continue;
- }
- if (!group.ContainsKey(input[0]))
- {
- string name = input[0];
- input.RemoveAt(0);
- List<DateTime> dates = new List<DateTime>();
- //List<DateTime> attendance = input.Select(x => DateTime.ParseExact(input.ToString(),@"dd/MM/yyyy", CultureInfo.InvariantCulture)).ToList();
- foreach(var date in input)
- {
- dates.Add(DateTime.ParseExact(date, @"dd/MM/yyyy", CultureInfo.InvariantCulture));
- }
- Student person = new Student();
- person.Name = name;
- person.Comments = new List<string>();
- person.Attendance = new List<DateTime>();
- person.Attendance.AddRange(dates);
- group.Add(name,person);
- }
- else
- {
- string name = input[0];
- input.RemoveAt(0);
- List<DateTime> dates = new List<DateTime>();
- foreach (var date in input)
- {
- dates.Add(DateTime.ParseExact(date, @"dd/MM/yyyy", CultureInfo.InvariantCulture));
- }
- group[name].Attendance.AddRange(dates);
- }
- input = Console.ReadLine().Split(new char[] { ' ', ',' }).ToList();
- }
- input = Console.ReadLine().Split('-').ToList();
- while(input[0]!="end of comments")
- {
- if (!group.ContainsKey(input[0]))
- {
- input = Console.ReadLine().Split('-').ToList();
- continue;
- }
- else
- {
- string name = input[0];
- string comment = input[1];
- if(group.ContainsKey(name))
- {
- Student student = group.Values.First(x => x.Name == name);
- if(student.Comments==null)
- student.Comments = new List<string>();
- student.Comments.Add(comment);
- }
- }
- input = Console.ReadLine().Split('-').ToList();
- }
- foreach(var kvp in group.Values.GroupBy(x=>x.Name).OrderBy(x=>x.Key))
- {
- foreach(var kid in kvp)
- {
- Console.WriteLine(kid.Name);
- Console.WriteLine("Comments:");
- foreach(var notes in kid.Comments.Where(x=>x.Length>0))
- Console.WriteLine($"- {notes}");
- Console.WriteLine("Dates attended:");
- foreach (var days in kid.Attendance.OrderBy(x => x.Date))
- {
- Console.WriteLine($"-- {days.ToString("dd/MM/yyyy")}");
- }
- }
- }
- Console.ReadLine();
- }
- }
- public class Student
- {
- public string Name { get; set; }
- public List<string> Comments { get; set; }
- public List<DateTime> Attendance { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement