Advertisement
martinvalchev

Book_Library

Feb 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.66 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. using System.Globalization;
  7.  
  8. namespace Book_Library
  9. {
  10.     class Program
  11.     {
  12.         static void Main(string[] args)
  13.         {
  14.             int n = int.Parse(Console.ReadLine());
  15.             List<Book> myBook = new List<Book>();
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 string[] input = Console.ReadLine().Split(' ').ToArray();
  19.                 Book book = new Book();
  20.                 book.Title = input[0];
  21.                 book.Author = input[1];
  22.                 book.Publisher = input[2];
  23.                 book.ReleaseDay = DateTime.ParseExact(input[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
  24.                 book.ISBN = input[4];
  25.                 book.Price = double.Parse(input[5]);
  26.  
  27.                 myBook.Add(book);
  28.  
  29.             }
  30.  
  31.             Library myLibrary = new Library();
  32.             myLibrary.Books = myBook;
  33.  
  34.             foreach (var book in myLibrary.Books.GroupBy(x => x.Author).OrderByDescending(x=>x.Sum(y=>y.Price)).ThenBy(x => x.Key))
  35.             {
  36.                 Console.WriteLine($"{book.Key} -> {book.Sum(x => x.Price):F2}");
  37.             }
  38.  
  39.  
  40.         }
  41.     }
  42.  
  43.     class Book
  44.     {
  45.         public string Title { get; set; }
  46.         public string Author { get; set; }
  47.         public string Publisher { get; set; }
  48.         public DateTime ReleaseDay { get; set; }
  49.         public string ISBN { get; set; }
  50.         public double Price { get; set; }
  51.     }
  52.  
  53.     class Library
  54.     {
  55.         public List<Book> Books { get; set; }
  56.         public string Name { get; set; }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement