Advertisement
StoyanGrigorov

Untitled

Oct 11th, 2016
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.04 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5. //08. MentorGroup
  6. namespace MentorGroup
  7. {
  8.     class MentorGroup
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             List<Student> students = new List<Student>();
  13.  
  14.             students = GetStudentsInfo();
  15.             PrintResults(students);
  16.         }
  17.  
  18.         private static void PrintResults(List<Student> students)
  19.         {
  20.             foreach (var stud in students.OrderBy(x => x.Name))
  21.             {
  22.                 Console.WriteLine(stud.Name);
  23.                 Console.WriteLine("Comments:");
  24.                 foreach (var com in stud.Comments)
  25.                 {
  26.                     Console.WriteLine($"- {com}");
  27.                 }
  28.                 Console.WriteLine("Dates attended:");
  29.                 foreach (var d in stud.Dates.Distinct().OrderBy(x => x))
  30.                 {
  31.                     Console.WriteLine($"-- {d.ToString("dd/MM/yyyy")}");
  32.                 }
  33.             }
  34.         }
  35.  
  36.         private static List<Student> GetStudentsInfo()
  37.         {
  38.             string command = Console.ReadLine();
  39.             List<Student> students = new List<Student>();
  40.  
  41.             while (command != "end of dates")
  42.             {
  43.                 List<string> usersDates = command.Split(',', ' ').ToList();
  44.                 string name = usersDates[0];
  45.                 usersDates.RemoveAt(0);
  46.                 List<DateTime> dates = usersDates.Select(x => DateTime.ParseExact(x, "dd/MM/yyyy", CultureInfo.InvariantCulture)).ToList();
  47.                 dates = dates.Distinct().ToList();
  48.  
  49.                 bool isRegistered = false;
  50.  
  51.                 foreach (var stud in students)
  52.                 {
  53.                     if (stud.Name == name)
  54.                     {
  55.                         isRegistered = true;
  56.                         stud.Dates.AddRange(dates);
  57.                         break;
  58.                     }
  59.                 }
  60.                 if (isRegistered == false)
  61.                 {
  62.                     Student student = new Student() { Name = name, Dates = dates , Comments = new List<string>()};
  63.                     students.Add(student);
  64.                 }
  65.                 command = Console.ReadLine();
  66.             }
  67.             command = Console.ReadLine();
  68.             while (command != "end of comments")
  69.             {
  70.                 string[] comments = command.Split('-');
  71.                 string name = comments[0];
  72.                 string comment = comments[1];
  73.  
  74.                 foreach (var stud in students)
  75.                 {
  76.                     if (stud.Name == name)
  77.                     {
  78.                         stud.Comments.Add(comment);
  79.                         break;
  80.                     }
  81.                 }
  82.                 command = Console.ReadLine();
  83.             }
  84.  
  85.             return students;
  86.         }
  87.     }
  88.  
  89.     class Student
  90.     {
  91.         public string Name { get; set; }
  92.         public List<string> Comments { get; set; }
  93.         public List<DateTime> Dates { get; set; }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement