Advertisement
Guest User

Book Library

a guest
Oct 15th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7.  
  8. class BookLibrary
  9. {
  10. static void Main()
  11. {
  12. List<Book> books = new List<Book>();
  13. books = ReadLibrary();
  14.  
  15. Dictionary<string, decimal> authors = new Dictionary<string,decimal>();
  16.  
  17. foreach (var entry in books)
  18. {
  19. if (!authors.ContainsKey(entry.Author))
  20. {
  21. authors.Add(entry.Author,0);
  22. }
  23. authors[entry.Author] += entry.Price;
  24. }
  25.  
  26. foreach (var entry in authors.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
  27. {
  28. string author = entry.Key;
  29. decimal totalPrice = entry.Value;
  30. Console.WriteLine($"{author} -> {totalPrice:f2}");
  31. }
  32. }
  33.  
  34. public static List<Book> ReadLibrary()
  35. {
  36. int n = int.Parse(Console.ReadLine());
  37. List<Book> lib = new List<Book>();
  38. for (int i = 0; i < n; i++)
  39. {
  40. Book book = ReadBook();
  41. lib.Add(book);
  42.  
  43. }
  44. return lib;
  45. }
  46.  
  47. public static Book ReadBook()
  48. {
  49. string[] inputData = Console.ReadLine().Split();
  50. Book book = new Book();
  51. book.Title = inputData[0];
  52. book.Author = inputData[1];
  53. book.Publisher = inputData[2];
  54. book.ReleaseDate = DateTime.ParseExact(inputData[3], "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
  55. book.ISBNNumber = inputData[4];
  56. book.Price = decimal.Parse(inputData[5]);
  57. return book;
  58. }
  59. }
  60.  
  61. class Book
  62. {
  63. public string Title { get; set; }
  64. public string Author { get; set; }
  65. public string Publisher { get; set; }
  66. public DateTime ReleaseDate { get; set; }
  67. public string ISBNNumber { get; set; }
  68. public decimal Price { get; set; }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement