Advertisement
Guest User

Untitled

a guest
Jun 15th, 2018
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.58 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace Mentor_Group
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             SortedDictionary<string, List<DateTime>> DataDictionary = new SortedDictionary<string, List<DateTime>>();
  13.             Dictionary<string, List<string>> ComentDictionary = new Dictionary<string, List<string>>();
  14.             while (true)
  15.             {
  16.                 string Input = Console.ReadLine();
  17.                 if (Input == "end of dates") break;
  18.                 string[] DataInput = Input.Split(new[] { ' ', ',' }, StringSplitOptions.RemoveEmptyEntries).ToArray();
  19.  
  20.                 string Name = DataInput[0];
  21.                 if (!DataDictionary.ContainsKey(Name))
  22.                 {
  23.                     List<DateTime> Data = new List<DateTime>();
  24.                     for (int i = 1; i < DataInput.Length; i++)
  25.                     {
  26.                         DateTime CurrentData = DateTime.ParseExact(DataInput[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  27.                         //if (!Data.Contains(CurrentData))
  28.                         //{
  29.                             Data.Add(CurrentData);
  30.                         //}
  31.  
  32.                     }
  33.                     DataDictionary.Add(Name, Data);
  34.                 }
  35.                 else
  36.                 {
  37.                     List<DateTime> Data = DataDictionary[Name];
  38.  
  39.                     for (int i = 1; i < DataInput.Length; i++)
  40.                     {
  41.                         DateTime CurrentData = DateTime.ParseExact(DataInput[i], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  42.                         //if (!Data.Contains(CurrentData))
  43.                         //{
  44.                             Data.Add(CurrentData);
  45.                         //}
  46.  
  47.                     }
  48.                     // DataDictionary.Add(Name, Data);
  49.                     DataDictionary[Name] = Data;
  50.                 }
  51.             }
  52.             while (true)
  53.             {
  54.                 string Input = Console.ReadLine();
  55.                 if (Input == "end of comments") break;
  56.                 string[] DataInput = Input.Split('-').ToArray();
  57.                 string Name = DataInput[0];
  58.                 string Coment = DataInput[1];
  59.                 if (!DataDictionary.ContainsKey(Name)) continue;
  60.                 if (!ComentDictionary.ContainsKey(Name))
  61.                 {
  62.  
  63.                     ComentDictionary.Add(Name, null);
  64.                     List<string> Bufera = new List<string>();
  65.                     Bufera.Add(Coment);
  66.                     ComentDictionary[Name] = Bufera;
  67.                 }
  68.                 else
  69.                 {
  70.                     ComentDictionary[Name].Add(Coment);
  71.                 }
  72.             }
  73.             foreach (var KVP in DataDictionary)
  74.             {
  75.                 Console.WriteLine(KVP.Key);
  76.                 Console.WriteLine("Comments:");
  77.                 if (ComentDictionary.ContainsKey(KVP.Key))
  78.                 {
  79.                     foreach (var coment in ComentDictionary[KVP.Key])
  80.                     {
  81.                         Console.WriteLine("- " + coment);
  82.                     }
  83.                 }
  84.                 Console.WriteLine("Dates attended:");
  85.                 List<DateTime> SortedData = DataDictionary[KVP.Key].ToList();
  86.                 SortedData = SortedData.OrderBy(n => n).ToList();
  87.                 foreach (var Data in SortedData)
  88.                 {
  89.  
  90.                     Console.WriteLine($"-- {Data:dd/MM/yyyy}");
  91.                 }
  92.             }
  93.         }
  94.     }
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement