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();
- Dictionary<string, decimal> authors = new Dictionary<string,decimal>();
- foreach (var entry in books)
- {
- if (!authors.ContainsKey(entry.Author))
- {
- authors.Add(entry.Author,0);
- }
- authors[entry.Author] += entry.Price;
- }
- foreach (var entry in authors.OrderByDescending(x=>x.Value).ThenBy(x=>x.Key))
- {
- string author = entry.Key;
- decimal totalPrice = entry.Value;
- 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