Advertisement
MartinPaunov

MentorGroup

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