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(string[] args)
- {
- int iteration = int.Parse(Console.ReadLine());
- List<Book> books = new List<Book>();
- Library library = new Library("Library", books);
- for (int i = 0; i < iteration; i++)
- {
- books.Add(ReadBook());
- }
- Console.WriteLine(library);
- }
- private static Book ReadBook()
- {
- string[] input = Console.ReadLine().Split().ToArray();
- return new Book(input[0], input[1], input[2],
- DateTime.ParseExact(input[3], "dd.MM.yyyy", CultureInfo.InvariantCulture),
- input[4], double.Parse(input[5]));
- }
- }
- 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 double Price { get; set; }
- public Book(string title, string author, string publisher, DateTime releaseDate, string ISBN, double price)
- {
- this.Title = title;
- this.Author = author;
- this.Publisher = publisher;
- this.ReleaseDate = releaseDate;
- this.ISBN = ISBN;
- this.Price = price;
- }
- }
- class Library
- {
- public string Name { get; set; }
- public List<Book> Books { get; set; }
- public Library(string name, List<Book> books)
- {
- this.Name = name;
- this.Books = books;
- }
- public override string ToString()
- {
- Dictionary<string, double> result = new Dictionary<string, double>();
- foreach (Book item in Books)
- {
- if(!result.ContainsKey(item.Author))
- {
- result.Add(item.Author, item.Price);
- }
- else
- {
- result[item.Author] += item.Price;
- }
- }
- string final = string.Join(Environment.NewLine, result.OrderByDescending(x => x.Value).ThenBy(x => x.Key).Select(x => new string($"{x.Key} -> {x.Value:f2}".ToCharArray())).ToArray());
- return final;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment