Advertisement
tanya_zheleva

Untitled

Feb 10th, 2017
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.62 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Linq;
  5.  
  6. namespace ExamPreparation
  7. {
  8.     public sealed class Student
  9.     {
  10.         public Student(string name)
  11.         {
  12.             this.Name = name;
  13.             this.Dates = new List<string>();
  14.             this.Comments = new List<string>();
  15.         }
  16.  
  17.         public string Name { get; private set; }
  18.  
  19.         public List<string> Dates { get; set; }
  20.  
  21.         public List<string> Comments { get; set; }
  22.  
  23.         public override string ToString()
  24.         {
  25.             StringBuilder output = new StringBuilder();
  26.             output.AppendLine(this.Name);
  27.             output.AppendLine("Comments:");
  28.  
  29.             foreach (var comment in this.Comments)
  30.             {
  31.                 output.AppendLine($"- {comment}");
  32.             }
  33.  
  34.             output.AppendLine("Dates attended:");
  35.             foreach (var date in this.Dates.OrderBy(d => d))
  36.             {
  37.                 output.AppendLine($"-- {date}");
  38.             }
  39.  
  40.             return output.ToString().Trim();
  41.         }
  42.     }
  43.  
  44.     public sealed class Preparation
  45.     {
  46.         public static void Main()
  47.         {
  48.             string datesInput = Console.ReadLine();
  49.             SortedDictionary<string, Student> students = new SortedDictionary<string, Student>();
  50.  
  51.             while (datesInput != "end of dates")
  52.             {
  53.                 string[] tokens = datesInput.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  54.                 string name = tokens[0];
  55.                 IEnumerable<string> dates = tokens.Skip(1);
  56.  
  57.                 if (!students.ContainsKey(name))
  58.                 {
  59.                     students.Add(name, new Student(name));
  60.                 }
  61.  
  62.                 foreach (var date in dates)
  63.                 {
  64.                     students[name].Dates.Add(date);
  65.                 }
  66.  
  67.                 datesInput = Console.ReadLine();
  68.             }
  69.  
  70.             string commentsInput = Console.ReadLine();
  71.  
  72.             while (commentsInput != "end of comments")
  73.             {
  74.                 string[] tokens = commentsInput.Split(new[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
  75.                 string name = tokens[0];
  76.                 string comment = tokens[1];
  77.  
  78.                 if (students.ContainsKey(name))
  79.                 {
  80.                     students[name].Comments.Add(comment);
  81.                 }
  82.  
  83.                 commentsInput = Console.ReadLine();
  84.             }
  85.  
  86.             foreach (var student in students)
  87.             {
  88.                 Console.WriteLine(student.Value);
  89.             }
  90.         }
  91.     }
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement