Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace _5.Book_Library
- {
- class Book
- {
- public string title { get; set; }
- public string author { get; set; }
- public string publisher { get; set; }
- public string releaseDate { get; set; }
- public string ISBNnumber { get; set; }
- public decimal price { get; set; }
- }
- class Library
- {
- public string name { get; set; }
- public List<Book> books { get; set; }
- }
- class BookLibrary
- {
- static void Main(string[] args)
- {
- Library myLibrary = new Library();
- myLibrary.books = new List<Book>();
- int numberOfBooks = int.Parse(Console.ReadLine());
- myLibrary.name = "Yavor's library";
- for (int book = 0; book < numberOfBooks; book++)
- {
- string[] data = Console.ReadLine().Split().ToArray();
- string title = data[0];
- string author = data[1];
- string publisher = data[2];
- string releaseDate = data[3];
- string ISBNnumber = data[4];
- decimal price = decimal.Parse(data[5]);
- Book myBook = new Book();
- myBook.title = title;
- myBook.author = author;
- myBook.publisher = publisher;
- myBook.releaseDate = releaseDate;
- myBook.ISBNnumber = ISBNnumber;
- myBook.price = price;
- myLibrary.books.Add(myBook);
- }
- var filteredBooks = myLibrary.books.
- Select(b => new
- {
- Author = b.author,
- EarningsTotal = myLibrary.books
- .Where(b1 => b1.author.Equals(b.author))
- .Sum(b1 => b1.price)
- })
- .Distinct()
- .OrderByDescending(b => b.EarningsTotal)
- .ThenBy(b => b.Author)
- .ToList();
- foreach (var book in filteredBooks)
- {
- Console.WriteLine("{0:f2} -> {1:f2}", book.Author, book.EarningsTotal);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement