Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class Program
- {
- public 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", System.Globalization.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);
- Dictionary<string, decimal> authors = new Dictionary<string,decimal>();
- foreach (Book item in books)
- {
- string authorName = book.Author;
- decimal bookPrice = book.Price;
- if (authors.ContainsKey(authorName) == false)
- {
- authors.Add(authorName,0);
- }
- authors[authorName] =authors[authorName]+ bookPrice;
- }
- }
- Dictionary<string, decimal> sortedAuthors = authors.OrderByDescending(a=>a.Value).ThenBy(a=>a.Key).ToDictionary(x=> x.Key, x=>x.Value);
- foreach (var author in sortedAuthors)
- {
- Console.WriteLine($"{author.Key} -> {author.Value:f2}");
- }
- }
- }
- public class Book
- {
- 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;}
- 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;
- }
- }
Add Comment
Please, Sign In to add comment