Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Globalization;
- using System.Text;
- using System.Threading.Tasks;
- using System.Numerics;
- namespace GettingBetter
- {
- class Program
- {
- public static void Main()
- {
- int numberOfBooks = int.Parse(Console.ReadLine());
- Library lib = new Library("books");
- for (int i = 0; i < numberOfBooks; i++)
- {
- var input = Console.ReadLine().Split(' ');
- Book newBook = new Book(input[0], input[1], input[2], input[3], input[4], decimal.Parse(input[5]));
- lib.Books.Add(newBook);
- }
- var sorted = lib.Books
- .OrderByDescending(p => p.Price)
- .ThenByDescending(a => a.Author)
- .ToList();
- var groups = sorted.GroupBy(p => p.Author);
- foreach (var group in groups)
- {
- decimal totalSum = 0;
- foreach (var item in group)
- {
- totalSum += item.Price;
- }
- Console.WriteLine("{0} -> {1}", group.Key, totalSum);
- }
- }
- }
- class Library
- {
- public string Name { get; set; }
- public List<Book> Books { get; set; }
- public Library(string name)
- {
- Books = new List<Book>();
- Name = name;
- }
- }
- class Book
- {
- public string Title { get; set; }
- public string Author { get; set; }
- public string Publisher { get; set; }
- public string ReleaseDate { get; set; }
- public string ISBN { get; set; }
- public decimal Price { get; set; }
- public Book(string title, string author, string publisher, string releasedate, string isbn, decimal price)
- {
- Title = title;
- Author = author;
- Publisher = publisher;
- ReleaseDate = releasedate;
- ISBN = isbn;
- Price = price;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement