Vladimir76

Mentor grup

Feb 10th, 2017
286
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Globalization;
  7.  
  8. namespace Mentor_Group
  9. {
  10.     class Mentor
  11.     {
  12.         public string Name { get; set; }
  13.         public List<string> comments { get; set; }
  14.         public List<DateTime> dates { get; set; }
  15.     }
  16.  
  17.     class Program
  18.     {
  19.         static void Main()
  20.         {
  21.             List<Mentor> mentorList = new List<Mentor>();
  22.             string input = Console.ReadLine();
  23.             do
  24.             {
  25.                 if (input=="end of dates")
  26.                 {
  27.                     break;
  28.                 }
  29.  
  30.                 string[] inputArr = input
  31.                     .Trim()
  32.                     .Split(new char[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries);
  33.                 string nameMentor = inputArr[0];
  34.                 DateTime date;
  35.  
  36.                 if (!mentorList.Any(x => x.Name == nameMentor))
  37.                 {
  38.                     Mentor user = new Mentor();
  39.                     user.dates = new List<DateTime>();
  40.                     user.comments = new List<string>();
  41.                     user.Name = nameMentor;
  42.                     if (inputArr.Length > 1)
  43.                     {
  44.                         for (int i = 1; i < inputArr.Length; i++)
  45.                         {
  46.                             date = DateTime.ParseExact(
  47.                                 inputArr[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  48.                             user.dates.Add(date);
  49.                         }
  50.  
  51.                     }
  52.                     mentorList.Add(user);
  53.                 }
  54.                 else
  55.                 {
  56.                     if (inputArr.Length > 1)
  57.                     {
  58.                         for (int i = 1; i < inputArr.Length; i++)
  59.                         {
  60.                             date = DateTime.ParseExact(
  61.                                 inputArr[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  62.                             if (!mentorList.Any(x => x.dates.Contains(date)))
  63.                             {
  64.                                 int index = mentorList.FindIndex(x => x.Name == nameMentor);
  65.                                 mentorList[index].dates.Add(date);
  66.                             }
  67.                         }
  68.                     }
  69.                 }
  70.  
  71.                 input = Console.ReadLine();
  72.  
  73.             } while (input!="end of dates");
  74.  
  75.             string inputComments = Console.ReadLine();
  76.  
  77.             do
  78.             {
  79.                 if (inputComments=="end of comments")
  80.                 {
  81.                     break;
  82.                 }
  83.                 string[] inputCommentsArr = inputComments
  84.                     .Trim()
  85.                     .Split('-');
  86.                 string name = inputCommentsArr[0];
  87.                 string comment = inputCommentsArr[1];
  88.  
  89.                 if (mentorList.Any(x => x.Name == name))
  90.                 {
  91.                     int index = mentorList.FindIndex(x => x.Name == name);
  92.                     mentorList[index].comments.Add(comment);
  93.                 }
  94.  
  95.                 inputComments = Console.ReadLine();
  96.             } while (inputComments!="end of comments");
  97.  
  98.             var sortMentorList = mentorList.OrderBy(x => x.Name).ToList();
  99.             foreach (var sml in sortMentorList)
  100.             {
  101.                 Console.WriteLine(sml.Name);
  102.                 Console.WriteLine("Comments:");
  103.                 foreach (var comment in sml.comments)
  104.                 {
  105.                     Console.WriteLine("- {0}",comment);
  106.                 }
  107.                 Console.WriteLine("Dates attended:");
  108.                 var sortDates = sml.dates.OrderBy(x => x).ToList();
  109.                 foreach (var date in sortDates)
  110.                 {
  111.                     Console.WriteLine("-- {0}",date.ToString("dd/MM/yyyy"));
  112.                 }
  113.             }
  114.         }
  115.     }
  116. }
Advertisement
Add Comment
Please, Sign In to add comment