Advertisement
Guest User

Untitled

a guest
Oct 23rd, 2017
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.47 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. namespace MentorGroup
  7. {
  8.     public class Student
  9.     {
  10.         public string Name { get; set; }
  11.         public List<DateTime> Date { get; set; }
  12.         public List<string> Comments { get; set; }
  13.     }
  14.  
  15.     class MainClass
  16.     {
  17.         public static void Main(string[] args)
  18.         {
  19.             List<Student> studentList = new List<Student>();
  20.             List<DateTime> dates = new List<DateTime>();
  21.             Student student = new Student();
  22.  
  23.             string input = Console.ReadLine();
  24.  
  25.             while (input != "end of dates")
  26.             {
  27.                  var line = input.Split(new char[] { ' ' },
  28.                                     StringSplitOptions
  29.                                     .RemoveEmptyEntries);
  30.  
  31.                 string name = line[0];
  32.                 student.Name = name;
  33.  
  34.                 if (line.Length > 1)
  35.                 {
  36.                     var dateString = line[1].Split(',').ToList();
  37.  
  38.  
  39.                     foreach (var item in dateString)
  40.                     {
  41.                         dates.Add(DateTime.ParseExact(item, "dd/MM/yyyy",
  42.                                                       CultureInfo
  43.                                                       .InvariantCulture));
  44.                     }
  45.  
  46.                     student.Date = dates;
  47.                 }
  48.                 studentList.Add(student);
  49.                 dates = new List<DateTime>();
  50.                 student = new Student();
  51.  
  52.                 input = Console.ReadLine();
  53.             }
  54.  
  55.             string comments = Console.ReadLine();
  56.  
  57.             while (comments != "end of comments")
  58.             {
  59.                 var arguments = comments.Split('-');
  60.                 var commentName = arguments[0];
  61.                 var commentNew = arguments[1];
  62.  
  63.                 foreach (var s in studentList)
  64.                 {
  65.                     if (s.Name == commentName)
  66.                     {
  67.                         if (s.Comments == null)
  68.                         {
  69.                             s.Comments = new List<string>();
  70.                             s.Comments.Add(commentNew);
  71.                         }
  72.                         else
  73.                         {
  74.                             s.Comments.Add(commentNew);
  75.                         }
  76.                     }
  77.                 }
  78.                 comments = Console.ReadLine();
  79.             }
  80.  
  81.             List<Student> sorted = studentList.OrderBy(x => x.Name)
  82.                                               .ThenBy(x => x.Date).ToList();
  83.  
  84.  
  85.  
  86.             foreach (var s in sorted)
  87.             {
  88.                 Console.WriteLine(s.Name);
  89.                 Console.WriteLine("Comments:");
  90.                 List<string> commentsList = s.Comments;
  91.  
  92.                 if (commentsList != null)
  93.                 {
  94.                     Console.WriteLine($"- {string.Join("",s.Comments)}");
  95.                 }
  96.  
  97.                 Console.WriteLine("Dates attended:");
  98.                 if (s.Date != null)
  99.                 {
  100.                     List<DateTime> date = s.Date.OrderBy(d => d.Date).ToList();
  101.                     if (date != null)
  102.                     {
  103.                         foreach (var d in date)
  104.                         {
  105.                             Console.WriteLine("-- " + d.ToString("dd/MM/yyyy"));
  106.                         }
  107.                     }
  108.                 }
  109.             }
  110.         }
  111.     }
  112. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement