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;
- using System.Globalization;
- namespace ObjectsAndClasses
- {
- public class StartUp
- {
- public static void Main()
- {
- SortedDictionary<string, decimal> results = new SortedDictionary<string, decimal>();
- Library library = new Library();
- Book newBook = new Book();
- int n = int.Parse(Console.ReadLine());
- for (int i = 0; i < n; i++)
- {
- newBook = ReadInput();
- library.Book.Add(newBook);
- if (!results.ContainsKey(newBook.Author))
- {
- results.Add(newBook.Author, newBook.Price);
- }
- else
- {
- results[newBook.Author] += newBook.Price;
- }
- }
- foreach (var result in results.OrderByDescending(x => x.Value))
- {
- Console.WriteLine($"{result.Key} -> {result.Value:F2}");
- }
- }
- private static Book ReadInput()
- {
- Book b = new Book();
- var input = Console.ReadLine()
- .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
- .ToArray();
- b.Title = input[0];
- b.Author = input[1];
- b.Publisher = input[2];
- b.ReleaseDate = DateTime.ParseExact(input[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
- b.ISBN = input[4];
- b.Price = decimal.Parse(input[5]);
- return b;
- }
- }
- class Library
- {
- public string Name { get; set; }
- public List<Book> Book { get; set; }
- public Library()
- {
- Book = new List<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 ISBN { get; set; }
- public decimal Price { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment