Advertisement
igrilkul

08. Mentor Group

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