Advertisement
PlamenMI81

05. Book Library

Oct 18th, 2017
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace _05_Book_Library
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.             int lines = int.Parse(Console.ReadLine());
  13.             List<Book> book=new List<Book>();
  14.             for (int i = 0; i < lines; i++)
  15.             {
  16.                 book.Add(ReadBook(Console.ReadLine()));
  17.             }
  18.             Library library = new Library() {Name = "Library",Books = book};
  19.  
  20.             foreach (var b in book.Select(x=>x.Autor).Distinct())
  21.             {
  22.                
  23.                 Console.WriteLine($"{string.Join("",b)} -> {/*КАК ДА СЛОЖА СУМАТА НА ЦЕНИТЕ ТУК, ПРИМЕРНО С ПОМОЩТА НА LINQ*/}");
  24.             }
  25.            
  26.         }
  27.  
  28.         private static Book ReadBook(string readLine)
  29.         {
  30.             string[] inputLine = readLine.Split();
  31.             var title = inputLine[0];
  32.             var autor = inputLine[1];
  33.             var pub = inputLine[2];
  34.             DateTime relDate = DateTime.ParseExact(inputLine[3], "dd.MM.yyyy",CultureInfo.InvariantCulture);
  35.             var isbn = inputLine[4];
  36.             var price = double.Parse(inputLine[5]);
  37.  
  38.             return new Book { Title = title,Autor = autor,Publisher = pub,ReleaseDate = relDate,ISBN = isbn,Price = price};
  39.         }
  40.     }
  41.  
  42.     class Book
  43.     {
  44.         public string Title { get; set; }
  45.         public string Autor { get; set; }
  46.         public string Publisher { get; set; }
  47.         public DateTime ReleaseDate { get; set; }
  48.         public string ISBN { get; set; }
  49.         public double Price { get; set; }
  50.     }
  51.  
  52.     class Library
  53.     {
  54.         public string Name { get; set; }
  55.         public List<Book> Books { get; set; }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement