Advertisement
YavorJS

Book Library Modification - 83%

Oct 12th, 2016
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.37 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Numerics;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10.  
  11.  
  12. class Book
  13. {
  14. public string title { get; set; }
  15. public string author { get; set; }
  16. public string publisher { get; set; }
  17. public DateTime releaseDate { get; set; }
  18. public string ISBNnumber { get; set; }
  19. public decimal price { get; set; }
  20. }
  21.  
  22. class Library
  23. {
  24. public string name { get; set; }
  25. public List<Book> books { get; set; }
  26. }
  27.  
  28. class BookLibrary
  29. {
  30. static void Main(string[] args)
  31. {
  32. Library myLibrary = new Library();
  33. myLibrary.books = new List<Book>();
  34. myLibrary.name = "Yavor's library";
  35. int numberOfBooks = int.Parse(Console.ReadLine());
  36. for (int book = 0; book < numberOfBooks; book++)
  37. {
  38. string[] data = Console.ReadLine().Split().ToArray();
  39. string title = data[0];
  40. string author = data[1];
  41. string publisher = data[2];
  42. DateTime releaseDate = DateTime.ParseExact(data[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
  43. string ISBNnumber = data[4];
  44. decimal price = decimal.Parse(data[5]);
  45. Book myBook = new Book();
  46. myBook.title = title;
  47. myBook.author = author;
  48. myBook.publisher = publisher;
  49. myBook.releaseDate = releaseDate;
  50. myBook.ISBNnumber = ISBNnumber;
  51. myBook.price = price;
  52. myLibrary.books.Add(myBook);
  53. }
  54. DateTime startDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", CultureInfo.InvariantCulture);
  55.  
  56. Dictionary<string, DateTime> filteredBooks = new Dictionary<string, DateTime>();
  57. for (int book = 0; book < myLibrary.books.Count; book++)
  58. {
  59. if (!filteredBooks.ContainsKey(myLibrary.books[book].title))
  60. {
  61. filteredBooks.Add(myLibrary.books[book].title, myLibrary.books[book].releaseDate);
  62. }
  63. }
  64.  
  65.  
  66. foreach (var book in filteredBooks.Where(x=>x.Value>startDate).OrderBy(x=>x.Value).ThenBy(x=>x.Key))
  67. {
  68. string date = book.Value.ToString("dd.MM.yyyy");
  69. Console.WriteLine("{0:f2} -> {1:f2}", book.Key, date);
  70. }
  71.  
  72. }
  73. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement