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;
- using System.Text;
- using System.Threading.Tasks;
- namespace Book_Library_Q
- {
- 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; }
- }
- class Library
- {
- public string Name { get; set; }
- public List<Book> Books { get; set; }
- }
- class Program
- {
- static void Main()
- {
- Dictionary<string, decimal> output = new Dictionary<string, decimal>();
- int num = int.Parse(Console.ReadLine());
- Library library = new Library();
- ImportBooks(library, num);
- foreach (string author in library.Books.Select(x => x.Author).Distinct())
- {
- output.Add(author, library.Books.Where(x => x.Author == author)
- .Select(x => x.Price)
- .Sum());
- }
- foreach (var pair in output.OrderByDescending(x => x.Value).ThenBy(x => x.Key))
- Console.WriteLine("{0} -> {1:f2}", pair.Key, pair.Value);
- }
- static void ImportBooks(Library library, int num)
- {
- for (int i = 0; i < num; i++)
- {
- library.Books = new List<Book>(); // Initialize the List before using it
- string[] input = Console.ReadLine().Split();
- library.Books.Add(new Book()
- {
- Title = input[0],
- Author = input[1],
- Publisher = input[2],
- ReleaseDate = DateTime.ParseExact(input[3], "dd.MM.yyyy", CultureInfo.InvariantCulture),
- ISBN = input[4],
- Price = decimal.Parse(input[5])
- });
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement