penkafileva

08. Mentor Group

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