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 TempDemo
- {
- class Program
- {
- static void Main(string[] args)
- {
- List<Student> studentGroup = new List<Student>();
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "end of dates")
- {
- break;
- }
- string[] tokens = command.Split(" ", StringSplitOptions.RemoveEmptyEntries);
- string name = tokens[0];
- List<string> tempDates = new List<string>();
- if (tokens.Length > 1)
- {
- tempDates = tokens[1].Split(',').ToList();
- }
- Student student = studentGroup.FirstOrDefault(x => x.Name == name);
- if (student == null)
- {
- var newStudent = new Student(name);
- for (int i = 0; i < tempDates.Count; i++)
- {
- DateTime parsedDate = DateTime.ParseExact(tempDates[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
- newStudent.Dates.Add(parsedDate);
- }
- studentGroup.Add(newStudent);
- }
- else
- {
- for (int i = 0; i < tempDates.Count; i++)
- {
- DateTime parsedDate = DateTime.ParseExact(tempDates[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
- student.Dates.Add(parsedDate);
- }
- }
- }
- while (true)
- {
- string command = Console.ReadLine();
- if (command == "end of comments")
- {
- break;
- }
- string[] tokens = command.Split('-', StringSplitOptions.RemoveEmptyEntries);
- string name = tokens[0];
- var student = studentGroup.FirstOrDefault(n => n.Name == name);
- if (student != null)
- {
- student.Comments.Add(tokens[1]);
- }
- }
- foreach (var student in studentGroup.OrderBy(n => n.Name))
- {
- Console.WriteLine(student.Name);
- Console.WriteLine("Comments:");
- foreach (var comment in student.Comments)
- {
- Console.WriteLine("- {0}", comment);
- }
- Console.WriteLine("Dates attended:");
- foreach (var date in student.Dates.OrderBy(d => d.Date))
- {
- Console.WriteLine("-- {0:dd/MM/yyyy}", date);
- }
- }
- }
- }
- class Student
- {
- public Student(string name)
- {
- this.Name = name;
- this.Dates = new List<DateTime>();
- this.Comments = new List<string>();
- }
- public string Name { get; set; }
- public List<DateTime> Dates = new List<DateTime>();
- public List<string> Comments = new List<string>();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement