MiroslavKisov

BookLibrary

Nov 1st, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.17 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Globalization;
  7.  
  8. namespace ObjectsAndClasses
  9. {
  10.     public class StartUp
  11.     {
  12.         public static void Main()
  13.         {
  14.             SortedDictionary<string, decimal> results = new SortedDictionary<string, decimal>();
  15.             Library library = new Library();
  16.             Book newBook = new Book();
  17.             int n = int.Parse(Console.ReadLine());
  18.             for (int i = 0; i < n; i++)
  19.             {
  20.                 newBook = ReadInput();
  21.                 library.Book.Add(newBook);
  22.                 if (!results.ContainsKey(newBook.Author))
  23.                 {
  24.                     results.Add(newBook.Author, newBook.Price);
  25.                 }
  26.                 else
  27.                 {
  28.                     results[newBook.Author] += newBook.Price;
  29.                 }
  30.             }
  31.             foreach (var result in results.OrderByDescending(x => x.Value))
  32.             {
  33.                 Console.WriteLine($"{result.Key} -> {result.Value:F2}");
  34.             }
  35.         }
  36.  
  37.         private static Book ReadInput()
  38.         {
  39.             Book b = new Book();
  40.             var input = Console.ReadLine()
  41.                     .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  42.                     .ToArray();
  43.             b.Title = input[0];
  44.             b.Author = input[1];
  45.             b.Publisher = input[2];
  46.             b.ReleaseDate = DateTime.ParseExact(input[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
  47.             b.ISBN = input[4];
  48.             b.Price = decimal.Parse(input[5]);
  49.             return b;
  50.         }
  51.  
  52.     }
  53.     class Library
  54.     {
  55.         public string Name { get; set; }
  56.         public List<Book> Book { get; set; }
  57.         public Library()
  58.         {
  59.             Book = new List<Book>();
  60.         }
  61.     }
  62.     class Book
  63.     {
  64.         public string Title { get; set; }
  65.         public string Author { get; set; }
  66.         public string Publisher { get; set; }
  67.         public DateTime ReleaseDate { get; set; }
  68.         public string ISBN { get; set; }
  69.         public decimal Price { get; set; }
  70.     }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment