YavorGrancharov

Register_Users(lambda)

Jul 17th, 2017
155
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace Register_Users
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             Dictionary<string, DateTime> users = new Dictionary<string, DateTime>();
  13.             string[] input = Console.ReadLine().Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  14.  
  15.             while (input[0] != "end")
  16.             {
  17.                 string user = input[0];
  18.                 DateTime date = DateTime.ParseExact(input[1], "dd/MM/yyyy", CultureInfo.InvariantCulture);
  19.  
  20.                 if (!users.ContainsKey(user))
  21.                 {
  22.                     users[user] = date;
  23.                 }
  24.                 input = Console.ReadLine().Split(new string[] { " -> " }, StringSplitOptions.RemoveEmptyEntries);
  25.             }
  26.  
  27.             foreach (var pair in users.Reverse().OrderBy(p => p.Value).Take(5).OrderByDescending(p => p.Value))
  28.             {
  29.                 Console.WriteLine("{0}", pair.Key);
  30.             }
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment