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;
- class BookLibrary
- {
- static void Main()
- {
- List<Book> books = new List<Book>();
- books = ReadLibrary();
- List<string> authors = books.Select(a => a.Author).Distinct().OrderBy(x => x).ToList();
- foreach (var author in authors)
- {
- decimal totalPrice = books.Where(b => b.Author.Equals(author)).Select(p => p.Price = p.Price).Sum();
- Console.WriteLine($"{author} -> {totalPrice:f2}");
- }
- }
- public static List<Book> ReadLibrary()
- {
- int n = int.Parse(Console.ReadLine());
- List<Book> lib = new List<Book>();
- for (int i = 0; i < n; i++)
- {
- Book book = ReadBook();
- lib.Add(book);
- }
- return lib;
- }
- public static Book ReadBook()
- {
- string[] inputData = Console.ReadLine().Split();
- Book book = new Book();
- book.Title = inputData[0];
- book.Author = inputData[1];
- book.Publisher = inputData[2];
- book.ReleaseDate = DateTime.ParseExact(inputData[3], "dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture);
- book.ISBNNumber = inputData[4];
- book.Price = decimal.Parse(inputData[5]);
- return book;
- }
- }
- class Book
- {
- public string Title { get; set; }
- public string Author { get; set; }
- public string Publisher { get; set; }
- public DateTime ReleaseDate { get; set; }
- public string ISBNNumber { get; set; }
- public decimal Price { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement