Advertisement
Kyojin96

Goran Help

Feb 13th, 2017
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Globalization;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Numerics;
  8.  
  9. namespace GettingBetter
  10. {
  11.     class Program
  12.     {
  13.         public static void Main()
  14.         {
  15.             int numberOfBooks = int.Parse(Console.ReadLine());
  16.             Library lib = new Library("books");
  17.             for (int i = 0; i < numberOfBooks; i++)
  18.             {
  19.                 var input = Console.ReadLine().Split(' ');
  20.                 Book newBook = new Book(input[0], input[1], input[2], input[3], input[4], decimal.Parse(input[5]));
  21.                 lib.Books.Add(newBook);
  22.             }
  23.             var sorted = lib.Books
  24.                 .OrderByDescending(p => p.Price)
  25.                 .ThenByDescending(a => a.Author)
  26.                 .ToList();
  27.  
  28.             var groups = sorted.GroupBy(p => p.Author);
  29.  
  30.             foreach (var group in groups)
  31.             {
  32.                 decimal totalSum = 0;
  33.                 foreach (var item in group)
  34.                 {
  35.                     totalSum += item.Price;
  36.                 }
  37.  
  38.                 Console.WriteLine("{0} -> {1}", group.Key, totalSum);
  39.             }
  40.            
  41.         }
  42.     }
  43.     class Library
  44.     {
  45.         public string Name { get; set; }
  46.         public List<Book> Books { get; set; }
  47.         public Library(string name)
  48.         {
  49.             Books = new List<Book>();
  50.             Name = name;
  51.         }
  52.     }
  53.     class Book
  54.     {
  55.         public string Title { get; set; }
  56.         public string Author { get; set; }
  57.         public string Publisher { get; set; }
  58.         public string ReleaseDate { get; set; }
  59.         public string ISBN { get; set; }
  60.         public decimal Price { get; set; }
  61.         public Book(string title, string author, string publisher, string releasedate, string isbn, decimal price)
  62.         {
  63.             Title = title;
  64.             Author = author;
  65.             Publisher = publisher;
  66.             ReleaseDate = releasedate;
  67.             ISBN = isbn;
  68.             Price = price;
  69.         }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement