Advertisement
simonradev

FixedCode

Feb 13th, 2017
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.86 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.  
  7. public class BookLibrary
  8. {
  9.     public static void Main(string[] args)
  10.     {
  11.         int input = int.Parse(Console.ReadLine());
  12.  
  13.         Library library = new Library();
  14.  
  15.         for (int i = 0; i < input; i++)
  16.         {
  17.             string[] command = Console.ReadLine().Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  18.             string title = command[0];
  19.             string author = command[1];
  20.             string publisher = command[2];
  21.             string releaseDate = command[3];
  22.             string isbn = command[4];
  23.             decimal price = decimal.Parse(command[5]);
  24.  
  25.             //идеята е че можеш да направиш всичко тук
  26.             //когато ти подадат нова книга проверяваш дали вече има такък автор
  27.             //и ако няма създаваш нова книга и я пъхаш в библиотеката
  28.             //обаче ако има трябва да намериш книгата чийто автор е същия от входа и да я ъпдейтнеш
  29.             Book book = null;
  30.             if (!library.Books.Any(b => b.Author == author))
  31.             {
  32.                 book = new Book(title, author, publisher, releaseDate, isbn, price);
  33.  
  34.                 library.Books.Add(book);
  35.             }
  36.             else
  37.             {
  38.                 book = library.Books.First(b => b.Author == author);
  39.                 book.Price += price;
  40.             }
  41.         }
  42.         //var results = library.Books.Where(a => a.Author.Equals(a.Author)).Distinct();
  43.  
  44.         //bookAuthors.OrderByDescending(b => b.Value).ThenBy(a => a.Key);
  45.  
  46.         foreach (var item in library.Books
  47.                                     .OrderByDescending(p => p.Price)
  48.                                     .ThenBy(a => a.Author))
  49.         {
  50.             var authors = item.Author;
  51.  
  52.             Console.WriteLine($"{authors} -> {item.Price:f2}");
  53.         }
  54.  
  55.     }
  56. }
  57. public class Library
  58. {
  59.     public string Name { get; set; }
  60.     public List<Book> Books { get; set; }
  61.  
  62.     public Library()
  63.     {
  64.         Books = new List<Book>();
  65.     }
  66. }
  67.  
  68. public class Book
  69. {
  70.     public string Title { get; set; }
  71.     public string Author { get; set; }
  72.     public string Publisher { get; set; }
  73.     public string ReleaseDate { get; set; }
  74.     public string ISBN { get; set; }
  75.     public decimal Price { get; set; }
  76.  
  77.     public Book(string title, string author, string publisher, string releaseDate, string isbn, decimal price)
  78.     {
  79.         this.Title = title;
  80.         this.Author = author;
  81.         this.Publisher = publisher;
  82.         this.ReleaseDate = releaseDate;
  83.         this.ISBN = isbn;
  84.         this.Price = price;
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement