tsekotsolov

Mentor Group

Oct 28th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace _08.MentroGroup
  7. {
  8.     class Program
  9.     {
  10.         const string Format = "dd/MM/yyyy";
  11.         static void Main(string[] args)
  12.         {
  13.            
  14.  
  15.             Dictionary<string, Student> studentsGroup = AddStudentsInGroup();
  16.  
  17.             AddComments(studentsGroup);
  18.  
  19.             PrintResults(studentsGroup);
  20.  
  21.         }
  22.  
  23.         private static void PrintResults(Dictionary<string, Student> studentsGroup)
  24.         {
  25.             foreach (var student in studentsGroup.OrderBy(x=>x.Key))
  26.             {
  27.                 Console.WriteLine(student.Key);
  28.                 Console.WriteLine("Comments:");
  29.                 if (student.Value.Comments.Count > 0)
  30.                 {
  31.                     Console.WriteLine($"- {string.Join("\n- ", student.Value.Comments)}");
  32.                 }
  33.                 Console.WriteLine("Dates attended:");
  34.                 if (student.Value.Dates.Count > 0)
  35.                 {
  36.                     foreach (var date in student.Value.Dates.OrderBy(x=>x.Date))
  37.                     {
  38.                         Console.WriteLine($"-- {date:dd/MM/yyyy}");
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.  
  44.         private static void AddComments(Dictionary<string, Student> studentsGroup)
  45.         {
  46.             string inputLine2 = Console.ReadLine();
  47.  
  48.             while (!inputLine2.Equals("end of comments"))
  49.             {
  50.                 string[] inputArr = inputLine2.Split('-');
  51.                 string commenter = inputArr[0];
  52.                 if (!studentsGroup.ContainsKey(commenter))
  53.                 {
  54.                     inputLine2 = Console.ReadLine();
  55.                     continue;
  56.                 }
  57.                 else
  58.                 {
  59.                     List<string> comments = new List<string>();
  60.                     comments.Add(inputArr[1]);
  61.                     studentsGroup[commenter].Comments.AddRange(comments);
  62.                 }
  63.  
  64.                 inputLine2 = Console.ReadLine();
  65.             }
  66.         }
  67.  
  68.         private static Dictionary<string, Student> AddStudentsInGroup()
  69.         {
  70.             Dictionary<string, Student> studentsGroup = new Dictionary<string, Student>();
  71.             string inputLine1 = Console.ReadLine();
  72.  
  73.             while (!inputLine1.Equals("end of dates"))
  74.             {
  75.  
  76.                 string[] inputToArr = inputLine1.Split(' ');
  77.  
  78.                 string name = inputToArr[0];
  79.  
  80.                 if (!studentsGroup.ContainsKey(name))
  81.                 {
  82.                     studentsGroup.Add(name, new Student());
  83.                     studentsGroup[name].Dates = new List<DateTime>();
  84.                     studentsGroup[name].Comments = new List<string>();
  85.                     studentsGroup[name].Name = name;
  86.                 }
  87.  
  88.                 if (inputToArr.Length < 2)
  89.                 {
  90.                     inputLine1 = Console.ReadLine();
  91.                     continue;
  92.                 }
  93.                 else
  94.                 {
  95.                     List<DateTime> dates =
  96.                         inputToArr[1].Split(',')
  97.                             .Select(x => DateTime.ParseExact(x, Format, CultureInfo.InvariantCulture))
  98.                             .ToList();
  99.                     studentsGroup[name].Dates.AddRange(dates);
  100.                 }
  101.  
  102.                 inputLine1 = Console.ReadLine();
  103.             }
  104.  
  105.             return studentsGroup;
  106.         }
  107.     }
  108.  
  109.     class Student
  110.     {
  111.        
  112.         public string Name { get; set; }
  113.         public List<string> Comments { get; set; }
  114.         public List<DateTime> Dates { get; set; }
  115.      
  116.     }
  117. }
Add Comment
Please, Sign In to add comment