sapphire123

Book Library

Aug 16th, 2017
238
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _05.Book_Library
  8. {
  9. class Book
  10. {
  11. public string Title { get; set; }
  12. public string Author { get; set; }
  13. public string Publisher { get; set; }
  14. public DateTime ReleaseDate { get; set; }
  15. public string ISBN_Number { get; set; }
  16. public double price { get; set; }
  17. }
  18.  
  19. class Program
  20. {
  21. static void Main(string[] args)
  22. {
  23. var n = int.Parse(Console.ReadLine());
  24. var authorDate = new Dictionary<string, DateTime>();
  25. for (int i = 0; i < n; i++)
  26. {
  27. var tokens = Console.ReadLine().Split().ToArray();
  28. var dates = tokens[3].Split(".".ToCharArray()).ToArray();
  29. var releaseDate = new DateTime
  30. (
  31. int.Parse(dates[2]),
  32. int.Parse(dates[1]),
  33. int.Parse(dates[0])
  34. );
  35. var book = new Book()
  36. {
  37. Title = tokens[0],
  38. Author = tokens[1],
  39. Publisher = tokens[2],
  40. ReleaseDate = releaseDate,
  41. ISBN_Number = tokens[4],
  42. price = double.Parse(tokens[5])
  43. };
  44.  
  45. if (!authorDate.ContainsKey(book.Title))
  46. {
  47. authorDate[book.Title] = new DateTime();
  48. }
  49. authorDate[book.Title] = book.ReleaseDate;
  50. }
  51. authorDate = authorDate.OrderBy(a => a.Value).ThenBy(a => a.Key)
  52. .ToDictionary(x => x.Key, x => x.Value);
  53.  
  54. var dateToPrintAfterTokens = Console.ReadLine().Split('.').ToArray();
  55. var dateToPrintAFter = new DateTime(
  56. int.Parse(dateToPrintAfterTokens[2]),
  57. int.Parse(dateToPrintAfterTokens[1]),
  58. int.Parse(dateToPrintAfterTokens[0]));
  59.  
  60. foreach (var authorAndDate in authorDate)
  61. {
  62. var author = authorAndDate.Key;
  63. var date = authorAndDate.Value;
  64. if (dateToPrintAFter < date)
  65. {
  66. Console.WriteLine($"{author} -> {date.ToString(@"dd.MM.yyyy")}");
  67. }
  68. }
  69.  
  70. }
  71. }
  72. }
RAW Paste Data