Advertisement
DaniPasteBin

Untitled

Jun 19th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5.  
  6. namespace _06.BookLibraryModification
  7. {
  8.     class Program
  9.     {
  10.         static void Main(string[] args)
  11.         {
  12.            
  13.  
  14.             int n = int.Parse(Console.ReadLine());
  15.             List<Book> books = new List<Book>();
  16.  
  17.             for (int i = 0; i < n; i++)
  18.             {
  19.                 string[] tokens = Console.ReadLine().Split(' ');
  20.                 string title = tokens[0];
  21.                 string author = tokens[1];
  22.                 string publisher = tokens[2];
  23.                 DateTime releaseDate = DateTime.ParseExact(tokens[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);  //парсвам във формат Дата
  24.                 string isbn = tokens[4];
  25.                 decimal price = decimal.Parse(tokens[5]); //парсвам стринга в decimal
  26.                                                           //следваща стъпка да направя книга
  27.                                                           //направих конструктор, който да приема всички стойности и да създава книга с тези стойности
  28.                 Book book = new Book(title, author, publisher, releaseDate, isbn, price);
  29.                 books.Add(book);
  30.             }
  31.             //въвеждам датата за филтриране
  32.             DateTime filterDate = DateTime.ParseExact(Console.ReadLine(),"dd.MM.yyyy",
  33.                 CultureInfo.InvariantCulture);
  34.             //да взема книгите които отговарят на условието да са издадени след подадената дата
  35.             List<Book>filteredBooks= books.Where(b => b.ReleaseDate > filterDate)
  36.                 .OrderBy(b => b.ReleaseDate)
  37.                 .ThenBy(b => b.Title)
  38.                 .ToList();
  39.             foreach (Book book in filteredBooks)
  40.             {
  41.                 Console.WriteLine($"{book.Title} -> {book.ReleaseDate:dd.MM.yyyy}");
  42.             }
  43.  
  44.  
  45.         }
  46.         class Book
  47.         {    //конструктор който сетва тези пропъртита
  48.  
  49.             public Book(string title, string author, string publisher, DateTime releaseDate, string isbn, decimal price)
  50.             {
  51.                 Title = title;
  52.                 Author = author;
  53.                 Publisher = publisher;
  54.                 ReleaseDate = releaseDate;
  55.                 Isbn = isbn;
  56.                 Price = price;
  57.             }
  58.  
  59.             public string Title { get; set; }
  60.             public string Author { get; set; }
  61.             public string Publisher { get; set; }
  62.             public DateTime ReleaseDate { get; set; }
  63.             public string Isbn { get; set; }
  64.             public decimal Price { get; set; }
  65.  
  66.         }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement