deleriumbg

Mentor Group

Jun 9th, 2018
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace Mentor_Group
  7. {
  8.     class Student
  9.     {
  10.         public string Name { get; set; }
  11.         public List<string> Comments { get; set; }
  12.         public List<DateTime> AttendanceDates { get; set; }
  13.     }
  14.  
  15.     class Program
  16.     {
  17.         static void Main(string[] args)
  18.         {
  19.             string input = Console.ReadLine();
  20.             List<Student> students = new List<Student>();
  21.  
  22.             while (input != "end of dates")
  23.             {
  24.                 Student student = new Student();
  25.  
  26.                 string[] studentInfo = input.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  27.                 string name = studentInfo[0];
  28.                 List<DateTime> dates = new List<DateTime>();
  29.                 dates = studentInfo[1].Split(',').Select(x => DateTime.ParseExact(x, "dd/MM/yyyy", CultureInfo.InvariantCulture)).ToList();
  30.  
  31.                 if (!students.Any(x => x.Name == name))
  32.                 {
  33.                     student.Name = name;
  34.                     student.AttendanceDates = dates;
  35.                     student.Comments = new List<string>();
  36.                     students.Add(student);
  37.                 }
  38.                 else
  39.                 {
  40.                     Student existingStudent = students.Find(x => x.Name == name);
  41.                     existingStudent.AttendanceDates.AddRange(dates);
  42.                 }
  43.  
  44.                 input = Console.ReadLine();
  45.             }
  46.  
  47.             string commentsInput = Console.ReadLine();
  48.  
  49.             while (commentsInput != "end of comments")
  50.             {
  51.                 string[] commentArgs = commentsInput.Split('-');
  52.                 string commentName = commentArgs[0];
  53.                 string comment = commentArgs[1];
  54.  
  55.                 if (students.Any(x => x.Name == commentName))
  56.                 {
  57.                     Student student = students.Find(x => x.Name == commentName);
  58.                     student.Comments.Add(comment);
  59.                 }
  60.  
  61.                 commentsInput = Console.ReadLine();
  62.             }
  63.  
  64.             foreach (var student in students.OrderBy(x => x.Name))
  65.             {
  66.                 Console.WriteLine(student.Name);
  67.  
  68.                 Console.WriteLine("Comments:");
  69.                 foreach (var comment in student.Comments)
  70.                 {
  71.                     Console.WriteLine($"- {comment}");
  72.                 }
  73.  
  74.                 Console.WriteLine("Dates attended:");
  75.                 foreach (var date in student.AttendanceDates.OrderBy(x => x))
  76.                 {
  77.                     Console.WriteLine($"-- {date.ToString("dd/MM/yyyy")}");
  78.                 }
  79.             }
  80.         }
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment