Advertisement
Guest User

Untitled

a guest
Oct 11th, 2016
768
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.35 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace BooksLibrary
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. int numOfBooks = int.Parse(Console.ReadLine());
  15. Library library = new Library();
  16. List<Book> books = new List<Book>();
  17. for (int i = 0; i < numOfBooks; i++)
  18. {
  19. Book book = ReadBook();
  20. books.Add(book);
  21. }
  22. library.Books = books;
  23. PrintBooks(library);
  24. }
  25.  
  26. private static void PrintBooks(Library library)
  27. {
  28. var ordered = library.Books.GroupBy(x => x.Author)
  29. .Select(g => new
  30. {
  31. Author = g.Key,
  32. Prices = g.Sum(s => s.Price)
  33. })
  34. .OrderByDescending(x=>x.Prices)
  35. .ThenBy(x=>x.Author)
  36. .ToList();
  37. foreach (var author in ordered)
  38. {
  39. Console.WriteLine("{0} -> {1}", author.Author, author.Prices);
  40. }
  41. }
  42. private static Book ReadBook()
  43. {
  44. Book book = new Book();
  45. string[] bookInfo = Console.ReadLine().Split().ToArray();
  46. book.Title = bookInfo[0];
  47. book.Author = bookInfo[1];
  48. book.Publisher = bookInfo[2];
  49. book.ReleaseDate = DateTime.ParseExact(bookInfo[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
  50. book.ISBN = bookInfo[4];
  51. book.Price = decimal.Parse(bookInfo[5], CultureInfo.InvariantCulture);
  52. return book;
  53. }
  54. }
  55.  
  56. class Library
  57. {
  58. string Name { get; set; }
  59. public List<Book> Books { get; set; }
  60. }
  61.  
  62. class Book
  63. {
  64. public string Title { get; set; }
  65. public string Author { get; set; }
  66. public string Publisher { get; set; }
  67. public DateTime ReleaseDate { get; set; }
  68. public string ISBN { get; set; }
  69. public decimal Price { get; set; }
  70.  
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement