simonradev

MentorGroup

Nov 28th, 2016
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.28 KB | None | 0 0
  1. using System.Linq;
  2. using System.Collections.Generic;
  3. using System;
  4. using System.Globalization;
  5.  
  6. namespace MentorGroup
  7. {
  8.     class Program
  9.     {
  10.         public static void Main(string[] args)
  11.         {
  12.             SortedDictionary<string, Student> students = new SortedDictionary<string, Student>();
  13.            
  14.             string attendancies = Console.ReadLine();
  15.             while (!attendancies.Equals("end of dates"))
  16.             {
  17.                 string[] nameAndDates;
  18.                 if (attendancies.Contains(" "))
  19.                 {
  20.                     nameAndDates = attendancies.Split(' ').ToArray();  
  21.                 }
  22.                 else
  23.                 {
  24.                     students.Add(attendancies, new Student());
  25.                     attendancies = Console.ReadLine();
  26.                     continue;
  27.                 }
  28.                
  29.                 string studentName = nameAndDates[0];
  30.                
  31.                 if (nameAndDates[1].Contains(","))
  32.                 {
  33.                     List<DateTime> dates = new List<DateTime>();
  34.                    
  35.                     string[] allDatesAttended = nameAndDates[1].Split(',');
  36.                    
  37.                     foreach (string date in allDatesAttended)
  38.                     {
  39.                         DateTime currentDate = DateTime.ParseExact(date, "dd/MM/yyyy", CultureInfo.InvariantCulture);
  40.                        
  41.                         dates.Add(currentDate);
  42.                     }
  43.                    
  44.                     if (!students.ContainsKey(studentName))
  45.                     {
  46.                         students.Add(studentName, new Student());
  47.                     }
  48.                    
  49.                     if (students[studentName].Attendancies == null)
  50.                     {
  51.                         students[studentName].Attendancies = new List<DateTime>();
  52.                     }
  53.                     students[studentName].Attendancies.AddRange(dates);
  54.                 }
  55.                 else
  56.                 {
  57.                     string dateAttended = nameAndDates[1];
  58.                    
  59.                     if (!students.ContainsKey(studentName))
  60.                     {
  61.                         students.Add(studentName, new Student());
  62.                     }
  63.                    
  64.                     if (students[studentName].Attendancies == null)
  65.                     {
  66.                         students[studentName].Attendancies = new List<DateTime>();
  67.                     }
  68.                     students[studentName].Attendancies.Add(DateTime.ParseExact(dateAttended, "dd/MM/yyyy", CultureInfo.InvariantCulture));
  69.                 }
  70.                
  71.                 attendancies = Console.ReadLine();
  72.             }
  73.            
  74.             string comments = Console.ReadLine();
  75.             while (!comments.Equals("end of comments"))
  76.             {
  77.                 string[] commentsInfo = comments.Split('-').ToArray();
  78.                
  79.                 string fromStudent = commentsInfo[0];
  80.                 string studentComment = commentsInfo[1];
  81.                
  82.                 if (!students.ContainsKey(fromStudent) || students[fromStudent].Attendancies == null)
  83.                 {
  84.                     comments = Console.ReadLine();
  85.                     continue;
  86.                 }
  87.                
  88.                 if (students[fromStudent].Comments == null)
  89.                 {
  90.                     students[fromStudent].Comments = new List<string>();
  91.                 }
  92.                 students[fromStudent].Comments.Add(studentComment);
  93.                
  94.                 comments = Console.ReadLine();
  95.             }
  96.            
  97.             foreach (KeyValuePair<string, Student> student in students)
  98.             {
  99.                 Console.WriteLine("{0}", student.Key);
  100.                 Console.WriteLine("Comments:");
  101.                
  102.                 if (student.Value.Comments != null)
  103.                 {
  104.                     foreach (string comment in student.Value.Comments)
  105.                     {
  106.                         Console.WriteLine("- {0}", comment);
  107.                     }
  108.                 }
  109.                
  110.                 Console.WriteLine("Dates attended:");
  111.                
  112.                 if (student.Value.Attendancies != null)
  113.                 {
  114.                     foreach (DateTime attendancy in student.Value.Attendancies.OrderBy(x => x.Date))
  115.                     {
  116.                         Console.WriteLine("-- {0}", attendancy.ToString("dd/MM/yyyy"));
  117.                     }  
  118.                 }
  119.                
  120.             }
  121.         }
  122.     }
  123.    
  124.     class Student
  125.     {
  126.         public List<string> Comments { get; set; }
  127.        
  128.         public List<DateTime> Attendancies { get; set; }
  129.     }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment