コード例 #1
0
        static void Main(string[] args)
        {
            Library library = new Library("Library");

            int booksCount = int.Parse(Console.ReadLine());

            for (int i = 0; i < booksCount; i++)
            {
                library.Books.Add(Book.Parse(Console.ReadLine()));
            }

            var result =
                library.Books.GroupBy(t => new { Author = t.Author })
                .Select(g => new
            {
                Average = g.Sum(p => p.Price),
                Author  = g.Key.Author
            })
                .ToDictionary(x => x.Author, x => x.Average)
                .OrderByDescending(x => x.Value)
                .ThenBy(x => x.Key);

            foreach (var pair in result)
            {
                Console.WriteLine($"{pair.Key} -> {pair.Value:f}");
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            Library library = new Library("Library");

            int booksCount = int.Parse(Console.ReadLine());


            for (int i = 0; i < booksCount; i++)
            {
                library.Books.Add(Book.Parse(Console.ReadLine()));
            }

            DateTime desiredDate = DateTime.ParseExact(Console.ReadLine(), "dd.MM.yyyy", CultureInfo.InvariantCulture);

            var result = library.Books.Where(b => b.ReleaseDate > desiredDate)
                         .OrderBy(b => b.ReleaseDate)
                         .ThenBy(b => b.Author);

            foreach (var book in result)
            {
                Console.WriteLine($"{book.Title} -> {book.ReleaseDate:dd.MM.yyyy}");
            }
        }