Advertisement
ramsess

Mentor Group

Jun 23rd, 2017
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.77 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5.  
  6. namespace Prob_08_Mentor_Group
  7. {
  8.     class MainClass
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             List<Mentor> Mentors = new List<Mentor>();
  13.             List<string> MentorsName = new List<string>();
  14.             List<Coment> Coments = new List<Coment>();
  15.  
  16.  
  17.             InputMentors(Mentors, MentorsName);
  18.             InputComents(MentorsName, Coments);
  19.             Output(Mentors, MentorsName, Coments);
  20.         }
  21.  
  22.         static void Output(List<Mentor> Mentors, List<string> MentorsName, List<Coment> Coments)
  23.         {
  24.             foreach (var mentorName in MentorsName)
  25.             {
  26.                 Console.WriteLine("{0}", mentorName);
  27.                 Console.WriteLine("Comments:");
  28.                 foreach (var coment in Coments.Where(a => a.MentorName == mentorName))
  29.                 {
  30.                     Console.WriteLine("- {0}", coment.ComentText);
  31.                 }
  32.                 Console.WriteLine("Dates attended:");
  33.                 foreach (var mentor in Mentors.Where(a => a.Name == mentorName))
  34.                 {
  35.                     mentor.Dates.Sort();
  36.                     foreach (var date in mentor.Dates)
  37.                     {
  38.                         Console.WriteLine("-- {0:dd/MM/yyyy}", date);
  39.                     }
  40.                 }
  41.             }
  42.         }
  43.  
  44.         static void InputComents(List<string> MentorsName, List<Coment> Coments)
  45.         {
  46.             var firstLine = Console.ReadLine();
  47.             while (firstLine != "end of comments")
  48.             {
  49.                 var line = firstLine.Split(new char[] { '-' }).ToList();
  50.                 if (MentorsName.Contains(line[0]))
  51.                 {
  52.                     if (line.Count != 1)
  53.                     {
  54.                         Coments.Add(new Coment(line[0], line[1]));
  55.                     }
  56.                 }
  57.                 firstLine = Console.ReadLine();
  58.             }
  59.         }
  60.  
  61.         static void InputMentors(List<Mentor> Mentors, List<string> MentorsName)
  62.         {
  63.             var firstLineMentor = Console.ReadLine();
  64.             while (firstLineMentor != "end of dates")
  65.             {
  66.                 var line = firstLineMentor.Split(new char[] { ' ', ',' }).ToList();
  67.                 int kk2 = MentorsName.IndexOf(line[0]);
  68.  
  69.                 List<DateTime> kk = new List<DateTime>();
  70.                 for (int i = 1; i < line.Count; i++)
  71.                 {
  72.                     if (kk2 == -1)
  73.                     {
  74.                         kk.Add(DateTime.ParseExact(line[i], "dd/MM/yyyy", CultureInfo.InvariantCulture));
  75.                     }
  76.                     else
  77.                     {
  78.                         Mentors[kk2].Dates.Add(DateTime.ParseExact(line[i], "dd/MM/yyyy", CultureInfo.InvariantCulture));
  79.                     }
  80.                 }
  81.  
  82.                 if (kk2 == -1)
  83.                 {
  84.                     Mentors.Add(new Mentor(line[0], kk));
  85.                     MentorsName.Add(line[0]);
  86.                 }
  87.                 firstLineMentor = Console.ReadLine();
  88.             }
  89.         }
  90.     }
  91.  
  92.     class Coment
  93.     {
  94.         public Coment(string mentorName, string comentText)
  95.         {
  96.             this.MentorName = mentorName;
  97.             this.ComentText = comentText;
  98.         }
  99.  
  100.                        
  101.         public string MentorName { get; set; }
  102.  
  103.         public string ComentText { get; set; }
  104.     }
  105.  
  106.     class Mentor
  107.     {
  108.         public Mentor(string name, List<DateTime> dates)
  109.         {
  110.             this.Name = name;
  111.             this.Dates = dates;
  112.         }
  113.  
  114.                        
  115.         public string Name { get; set; }
  116.  
  117.         public List<DateTime> Dates { get; set; }
  118.     }
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement