Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Globalization;
- using System.Text;
- namespace ExamPreparation
- {
- public sealed class Book
- {
- public Book(string title, DateTime releaseDate)
- {
- this.Title = title;
- this.ReleaseDate = releaseDate;
- }
- public string Title { get; private set; }
- public DateTime ReleaseDate { get; set; }
- public override string ToString()
- {
- return $"{this.Title} -> {this.ReleaseDate.ToString("dd.MM.yyyy")}";
- }
- }
- public sealed class Library
- {
- public Library()
- {
- this.Books = new List<Book>();
- }
- public List<Book> Books { get; set; }
- public string ReleasedBooks(DateTime endDate)
- {
- StringBuilder output = new StringBuilder();
- IEnumerable<Book> releasedAfter = this.Books.Where(b => b.ReleaseDate > endDate);
- foreach (var book in releasedAfter.OrderBy(b => b.ReleaseDate).ThenBy(b => b.Title))
- {
- output.AppendLine(book.ToString());
- }
- return output.ToString().Trim();
- }
- }
- public sealed class Startup
- {
- public static void Main()
- {
- int n = int.Parse(Console.ReadLine());
- Library library = new Library();
- for (int i = 0; i < n; i++)
- {
- string[] tokens = Console.ReadLine().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
- string title = tokens[0];
- DateTime releaseDate = DateTime.ParseExact(tokens[3], "dd.MM.yyyy", CultureInfo.InvariantCulture);
- Book book = new Book(title, releaseDate);
- if (library.Books.Contains(book))
- {
- library.Books.Find(b => b.Title == title).ReleaseDate = releaseDate;
- }
- else
- {
- library.Books.Add(book);
- }
- }
- DateTime endDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", CultureInfo.InvariantCulture);
- string releasedBooks = library.ReleasedBooks(endDate);
- Console.WriteLine(releasedBooks);
- }
- }
- }
Add Comment
Please, Sign In to add comment