Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- namespace _05_BookLibrary
- {
- class Program
- {
- static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- List<Book> books = new List<Book>();
- for (int i = 0; i < n; i++)
- {
- string[] tokens = Console.ReadLine().Split();
- string title = tokens[0];
- string author = tokens[1];
- string publisher = tokens[2];
- DateTime releaseDate = DateTime.ParseExact(tokens[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
- string isbn = tokens[4];
- decimal price = decimal.Parse(tokens[5]);
- Book book = new Book(title, author, publisher, releaseDate, isbn, price);
- books.Add(book);
- }
- var authors = new Dictionary<string, decimal>();
- foreach (Book book in books)
- {
- if (authors.ContainsKey(book.Author) == false)
- {
- authors.Add(book.Author, book.Price);
- }
- else
- {
- authors[book.Author] += book.Price;
- }
- }
- var sortedAuthors = authors
- .OrderByDescending(p => p.Value)
- .ThenBy(a => a.Key)
- .ToDictionary(d => d.Key, d => d.Value);
- foreach (var author in sortedAuthors)
- {
- Console.WriteLine($"{author.Key} -> {author.Value:f2}");
- }
- }
- }
- public class Book
- {
- public Book(string title, string author, string publisher, DateTime releaseDate, string isbn, decimal price)
- {
- Title = title;
- Author = author;
- Publisher = publisher;
- ReleaseDate = releaseDate;
- Isbn = isbn;
- Price = price;
- }
- public string Title { get; set; }
- public string Author { get; set; }
- public string Publisher { get; set; }
- public DateTime ReleaseDate { get; set; }
- public string Isbn { get; set; }
- public decimal Price { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement