Advertisement
YavorJS

Book Library - Dictionary

Oct 12th, 2016
613
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 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 string 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. int numberOfBooks = int.Parse(Console.ReadLine());
  35. for (int book = 0; book < numberOfBooks; book++)
  36. {
  37. string[] data = Console.ReadLine().Split().ToArray();
  38. string title = data[0];
  39. string author = data[1];
  40. string publisher = data[2];
  41. string releaseDate = data[3];
  42. string ISBNnumber = data[4];
  43. decimal price = decimal.Parse(data[5]);
  44. Book myBook = new Book();
  45. myBook.title = title;
  46. myBook.author = author;
  47. myBook.publisher = publisher;
  48. myBook.releaseDate = releaseDate;
  49. myBook.ISBNnumber = ISBNnumber;
  50. myBook.price = price;
  51. myLibrary.books.Add(myBook);
  52. }
  53.  
  54. Dictionary<string, decimal> filteredBooks = new Dictionary<string, decimal>();
  55. for (int book = 0; book < myLibrary.books.Count; book++)
  56. {
  57. if (!filteredBooks.ContainsKey(myLibrary.books[book].author))
  58. {
  59. filteredBooks.Add(myLibrary.books[book].author, 0);
  60. }
  61. filteredBooks[myLibrary.books[book].author] += myLibrary.books[book].price;
  62. }
  63.  
  64.  
  65. foreach (var book in filteredBooks.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  66. {
  67. Console.WriteLine("{0:f2} -> {1:f2}", book.Key, book.Value);
  68. }
  69.  
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement